OpenAPITools / OpenAPITools/openapi-generator
[BUG] Objects pickled with one version cannot be unpickled in another version
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
To reproduce:
pip install kubernetes==17.17.0
Now run this
import pickle
from kubernetes.client import models as k8s
pod = k8s.V1PodSpec(hostname="hi", containers=[])
pickle.dumps(pod)
Now create a new virtualenv with latest version of kubernetes.
Now try to unpickle:
import pickle
val = b"\x80\x04\x95#\x06\x00\x00\x00\x00\x00\x00\x8c$kubernetes.client.models.v1_pod_spec\x94\x8c\tV1PodSpec\x94\x93\x94)\x81\x94}\x94(\x8c\x18local_vars_configuration\x94\x8c\x1fkubernetes.client.configuration\x94\x8c\rConfiguration\x94\x93\x94)\x81\x94}\x94(\x8c\x04host\x94\x8c\x10http://localhost\x94\x8c\x10temp_folder_path\x94N\x8c\x07api_key\x94}\x94\x8c\x0eapi_key_prefix\x94}\x94\x8c\x14refresh_api_key_hook\x94N\x8c\x08username\x94N\x8c\x08password\x94N\x8c\x14discard_unknown_keys\x94\x89\x8c\x06logger\x94}\x94(\x8c\x0epackage_logger\x94\x8c\x07logging\x94\x8c\tgetLogger\x94\x93\x94\x8c\x06client\x94\x85\x94R\x94\x8c\x0eurllib3_logger\x94h\x1b\x8c\x07urllib3\x94\x85\x94R\x94u\x8c\x1d_Configuration__logger_format\x94\x8c%%(asctime)s %(levelname)s %(message)s\x94\x8c\x10logger_formatter\x94h\x19\x8c\tFormatter\x94\x93\x94)\x81\x94}\x94(\x8c\x06_style\x94h\x19\x8c\x0cPercentStyle\x94\x93\x94)\x81\x94}\x94\x8c\x04_fmt\x94h$sbh/h$\x8c\x07datefmt\x94Nub\x8c\x15logger_stream_handler\x94N\x8c\x13logger_file_handler\x94N\x8c\x1b_Configuration__logger_file\x94N\x8c\x15_Configuration__debug\x94\x89\x8c\nverify_ssl\x94\x88\x8c\x0bssl_ca_cert\x94N\x8c\tcert_file\x94N\x8c\x08key_file\x94N\x8c\x0fassert_hostname\x94N\x8c\x17connection_pool_maxsize\x94KP\x8c\x05proxy\x94N\x8c\rproxy_headers\x94N\x8c\x19safe_chars_for_path_param\x94\x8c\x00\x94\x8c\x07retries\x94N\x8c\x16client_side_validation\x94\x88ub\x8c\x18_active_deadline_seconds\x94N\x8c\t_affinity\x94N\x8c _automount_service_account_token\x94N\x8c\x0b_containers\x94]\x94\x8c\x0b_dns_config\x94N\x8c\x0b_dns_policy\x94N\x8c\x15_enable_service_links\x94N\x8c\x15_ephemeral_containers\x94N\x8c\r_host_aliases\x94N\x8c\t_host_ipc\x94N\x8c\r_host_network\x94N\x8c\t_host_pid\x94N\x8c\t_hostname\x94\x8c\x02hi\x94\x8c\x13_image_pull_secrets\x94N\x8c\x10_init_containers\x94N\x8c\n_node_name\x94N\x8c\x0e_node_selector\x94N\x8c\t_overhead\x94N\x8c\x12_preemption_policy\x94N\x8c\t_priority\x94N\x8c\x14_priority_class_name\x94N\x8c\x10_readiness_gates\x94N\x8c\x0f_restart_policy\x94N\x8c\x13_runtime_class_name\x94N\x8c\x0f_scheduler_name\x94N\x8c\x11_security_context\x94N\x8c\x10_service_account\x94N\x8c\x15_service_account_name\x94N\x8c\x18_share_process_namespace\x94N\x8c\n_subdomain\x94N\x8c!_termination_grace_period_seconds\x94N\x8c\x0c_tolerations\x94N\x8c\x1c_topology_spread_constraints\x94N\x8c\x08_volumes\x94N\x8c\rdiscriminator\x94Nub."
pickle.loads(val)
You will get an error:
pickle.loads(val)
Traceback (most recent call last):
File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/code.py", line 90, in runcode
exec(code, self.locals)
File "<input>", line 1, in <module>
File "/Users/dstandish/.virtualenvs/local/lib/python3.8/site-packages/kubernetes/client/models/v1_pod_spec.py", line 1081, in __repr__
return self.to_str()
File "/Users/dstandish/.virtualenvs/local/lib/python3.8/site-packages/kubernetes/client/models/v1_pod_spec.py", line 1077, in to_str
return pprint.pformat(self.to_dict())
File "/Users/dstandish/.virtualenvs/local/lib/python3.8/site-packages/kubernetes/client/models/v1_pod_spec.py", line 1056, in to_dict
value = getattr(self, attr)
File "/Users/dstandish/.virtualenvs/local/lib/python3.8/site-packages/kubernetes/client/models/v1_pod_spec.py", line 626, in os
return self._os
AttributeError: 'V1PodSpec' object has no attribute '_os'
The problem is that in to_dict in every object, getattr is called without a default of none for each of the current openapi_types. But these don't all exist on the object pickled in the old version.
So we should add a default of None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the kubernetes==17.17.0 pickle and the latest version, then locate the generated model to_dict methods that iterate over current openapi_types. The change is done when an object pickled by the older version can be unpickled and inspected without the missing-attribute error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kubernetes, openapi, python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100