python icon indicating copy to clipboard operation
python copied to clipboard

sanitize_for_serialization returns empty Dict when all values are None

Open Uranium2 opened this issue 2 years ago • 0 comments

What happened: I'm trying to monitor my Jobs with read_namespaced_job_status and return the status in Dict/Json format. When I create the Job and get it's status just after (under 5/10 seconds before real creation on Cluster) I get a status of Dict where all values are None, which is fine. But when I try to sanitize_for_serialization it, I get an empty Dict.

> from kubernetes import client
> from kubernetes.client import ApiClient

> batch_v1 = client.BatchV1Api()
> api_response = batch_v1.read_namespaced_job_status(name="job-1", namespace="my-namespace")
> print(api_response)
{'active': None,
 'completed_indexes': None,
 'completion_time': None,
 'conditions': None,
 'failed': None,
 'ready': None,
 'start_time': None,
 'succeeded': None,
 'uncounted_terminated_pods': None}
> api = ApiClient()
> api_response_status_dict = api.sanitize_for_serialization(api_response.status)
> print(api_response_status_dict)
{}

What you expected to happen: I expected api_response_status_dict to be a non empty Dict, with all keys and with values to None.

Environment:

  • Kubernetes version: v1.23.5
  • OS : Ubuntu 20.04.3 LTS (WSL1)
  • Python version : Python 3.8.10
  • Python client version: 23.3.0

Uranium2 avatar Jun 28 '22 08:06 Uranium2