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

error in create_namespaced_job 'property' - object has no attribute 'swagger_types' #872

Closed
simondh opened this issue Jul 12, 2019 · 6 comments

Comments

@simondh
Copy link

simondh commented Jul 12, 2019

error in create_namespaced_job
'property' object has no attribute 'swagger_types'

I have traced this to an error in /kubernetes/client/api_client.py, sanitize_for_serialization, where the recursion calls this function to 'sanitize' a single entity of type Property. This falls through to the obj_dict comprehension, where it bombs as the object has no .swagger_type attibute.
I have fixed it locally with this change (2 lines in bold). The code that triggers the issue is attached
k8-python-error.txt. I can submit a pull request if desired.

    if isinstance(obj, dict):
        obj_dict = obj
    **elif isinstance(obj, property):
        return None**
    else:
        # Convert model obj to dict except
        # attributes `swagger_types`, `attribute_map`
        # and attributes which value is not None.
        # Convert attribute name to json key in
        # model definition for request.
        obj_dict = {obj.attribute_map[attr]: getattr(obj, attr)
                    for attr, _ in iteritems(obj.swagger_types)
                    if getattr(obj, attr) is not None}
@roycaihw
Copy link
Member

/cc

@roycaihw
Copy link
Member

roycaihw commented Jul 16, 2019

thanks for the report!

I looked at k8-python-error.txt and I'm not sure if it's a bug in api_client.py

I pulled together a small example mimicking the k8s doc and it worked for me:

from kubernetes import client, config
from pprint import pprint

def main():
    config.load_kube_config()
    container = client.V1Container(name="pi", image="perl",
        command=["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"])
    template = client.V1PodTemplateSpec(spec=client.V1PodSpec(containers=[container], restart_policy="Never"))
    job = client.V1Job(api_version="batch/v1", kind="Job",
        metadata=client.V1ObjectMeta(name="pi"),
        spec=client.V1JobSpec(template=template, backoff_limit=4))
    batch_v1 = client.BatchV1Api()
    api_response = batch_v1.create_namespaced_job(body=job, namespace="default")
    pprint(api_response)

if __name__ == '__main__':
    main()
$ kubectl get jobs
NAME   COMPLETIONS   DURATION   AGE
pi     1/1           7s         9s

@roycaihw
Copy link
Member

perhaps we could add some examples like ^ given job creation with the python client is painful

ref #589
https://blog.pythian.com/how-to-create-kubernetes-jobs-with-python/

cc @scottilee

@scottilee
Copy link
Contributor

@roycaihw Added it to my list of examples to add and clean up. You can close this if you want.

@roycaihw
Copy link
Member

/close

@k8s-ci-robot
Copy link
Contributor

@roycaihw: Closing this issue.

In response to this:

/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants