Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model objects should tolerate None in place of empty lists #376

Closed
jgiles opened this issue Oct 31, 2017 · 15 comments
Closed

Model objects should tolerate None in place of empty lists #376

jgiles opened this issue Oct 31, 2017 · 15 comments
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. help-needed kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@jgiles
Copy link

jgiles commented Oct 31, 2017

Python client version: 4.0.0a1
Server version: 1.8.0

On an endpoints request, Kubernetes 1.8 will return "subsets": null in the case of an empty subsets list. This leads to an error on deserialization:

File "/usr/local/lib/python3.6/dist-packages/kubernetes/watch/watch.py", line 119, in stream                                                                                                                                                    yield self.unmarshal_event(line, return_type)                                                                                                                                                                                               File "/usr/local/lib/python3.6/dist-packages/kubernetes/watch/watch.py", line 83, in unmarshal_event
    js['object'] = self._api_client.deserialize(obj, return_type)                                                                                                                                                                               File "/usr/local/lib/python3.6/dist-packages/kubernetes/client/api_client.py", line 236, in deserialize                                                                                                                                         return self.__deserialize(data, response_type)
  File "/usr/local/lib/python3.6/dist-packages/kubernetes/client/api_client.py", line 276, in __deserialize
    return self.__deserialize_model(data, klass)
  File "/usr/local/lib/python3.6/dist-packages/kubernetes/client/api_client.py", line 622, in __deserialize_model
    instance = klass(**kwargs)
  File "/usr/local/lib/python3.6/dist-packages/kubernetes/client/models/v1_endpoints.py", line 64, in __init__
    self.subsets = subsets
  File "/usr/local/lib/python3.6/dist-packages/kubernetes/client/models/v1_endpoints.py", line 156, in subsets
    raise ValueError("Invalid value for `subsets`, must not be `None`")
ValueError: Invalid value for `subsets`, must not be `None`

See related Kubernetes issue: kubernetes/kubernetes#44593
However, that issue was eventually resolved by declaring that as clients should treat nulls and empty lists as interchangeable unless specified otherwise:
kubernetes/kubernetes#45294

The Python client should remove the none-checks, or possibly translate them to empty lists (though if they decided against that on the server-side, it sounds risky).

jgiles added a commit to paxosglobal/client-python that referenced this issue Oct 31, 2017
This is a hacky workaround for:
kubernetes-client#376

The client code is generated and should not be manually edited like
this, but the error is blocking our use of the library.
@mildebrandt
Copy link

Same problem with CRD requests:

  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/models/v1beta1_custom_resource_definition_status.py", line 53, in __init__
    self.conditions = conditions
  File "/usr/local/lib/python3.6/site-packages/kubernetes/client/models/v1beta1_custom_resource_definition_status.py", line 101, in conditions
    raise ValueError("Invalid value for `conditions`, must not be `None`")
ValueError: Invalid value for `conditions`, must not be `None`

CyberDem0n pushed a commit to patroni/patroni that referenced this issue Nov 23, 2017
The lates one has some problems with none values received instead of
empty list:
kubernetes-client/python#376
@jgiles
Copy link
Author

jgiles commented Dec 20, 2017

@yliaog ping? This is going to become a larger problem as more people start to use Kubernetes 1.8.

jgiles added a commit to paxosglobal/client-python that referenced this issue Dec 20, 2017
This is a hacky workaround for:
kubernetes-client#376

The client code is generated and should not be manually edited like
this, but the error is blocking our use of the library.
@yliaog
Copy link
Contributor

yliaog commented Dec 20, 2017

cc @mbohlool for his comments

@mbohlool
Copy link
Contributor

mbohlool commented Jan 4, 2018

That is an interesting problem and I keep going back and forth between main repo or swagger-codegen as the place to fix this. Problem is do we assume a required array can be empty or not. Seems that kubernetes API server think that is OK but swagger-codegen assume the other one.

I would say the best fix should be in kubernetes main repo, e.g. if an array can be empty, it should not be required. I suggest you file an issue in the main repo and see if we can get a fix there in 1.10.

As a temporary fix, we can patch the spec in the kubernetes-client/gen repo.

@salilgupta1
Copy link

salilgupta1 commented Jan 30, 2018

Just to piggy back off this issue. I'm seeing a similar error with the list_event_for_all_namespaces endpoint.
"ValueError: Invalid value for involved_object, must not be None"

python client: 4.0.0
K8s API Version: 1.6.4

I did not see this issue when were using the 2.2.0 of the python client.

@hanikesn
Copy link

hanikesn commented Mar 8, 2018

For anyone looking for an easy workaround. You can easily monkey patch the class giving you errors:

from kubernetes.client.models.v1_endpoints import V1Endpoints
def set_subsets(self, subsets):
    if subsets is None:
        subsets = []
    self._subsets = subsets
setattr(V1Endpoints, 'subsets', property(fget=V1Endpoints.subsets.fget, fset=set_subsets))

@mward29
Copy link

mward29 commented Jul 11, 2018

Running into this problem regularly with respect to CRDs.

Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.0", GitCommit:"91e7b4fd31fcd3d5f436da26c980becec37ceefe", GitTreeState:"clean", BuildDate:"2018-06-27T20:17:28Z", GoVersion:"go1.10.2", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:44:10Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}

@karmab
Copy link

karmab commented Oct 8, 2018

same issue and workaround didnt work for me....

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 26, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels May 26, 2019
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ashpreetbedi
Copy link

/reopen

@k8s-ci-robot
Copy link
Contributor

@ashpreetbedi: You can't reopen an issue/PR unless you authored it or you are a collaborator.

In response to this:

/reopen

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@ashpreetbedi
Copy link

@mbohlool this issue is there when creating CRDs as well. How can we get this fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. help-needed kind/bug Categorizes issue or PR as related to a bug. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests