dstandish commented on code in PR #28454:
URL: https://github.com/apache/airflow/pull/28454#discussion_r1051910861
##########
airflow/utils/sqlalchemy.py:
##########
@@ -153,6 +158,75 @@ def process_result_value(self, value, dialect):
return BaseSerialization.deserialize(value)
+def sanitize_for_serialization(obj: V1Pod):
+ """
+ Convert pod to dict.... but *safely*.
+
+ When pod objects created with one k8s version are unpickled in a python
+ env with a more recent k8s version (in which the object attrs may have
+ changed) the unpickled obj may throw an error because the attr
+ expected on new obj may not be there on the unpickled obj.
+
+ This function still converts the pod to a dict; the only difference is
+ it populates missing attrs with None.
+
+ If obj is None, return None.
+ If obj is str, int, long, float, bool, return directly.
+ If obj is datetime.datetime, datetime.date
+ convert to string in iso8601 format.
+ If obj is list, sanitize each element in the list.
+ If obj is dict, return the dict.
+ If obj is OpenAPI model, return the properties dict.
+
+ :param obj: The data to serialize.
+ :return: The serialized form of data.
+
+ :meta private:
+ """
+ if obj is None:
+ return None
+ elif isinstance(obj, PRIMITIVE_TYPES):
+ return obj
+ elif isinstance(obj, list):
+ return [sanitize_for_serialization(sub_obj) for sub_obj in obj]
+ elif isinstance(obj, tuple):
+ return tuple(sanitize_for_serialization(sub_obj) for sub_obj in obj)
+ elif isinstance(obj, (datetime.datetime, datetime.date)):
+ return obj.isoformat()
+
+ if isinstance(obj, dict):
+ obj_dict = obj
+ else:
+ obj_dict = {
+ obj.attribute_map[attr]: getattr(obj, attr)
+ for attr, _ in obj.openapi_types.items()
+ if getattr(obj, attr, None) is not None
Review Comment:
only difference is this line, where we have a default of None
compare with
[here](https://github.com/kubernetes-client/python/blob/5a96bbcbe21a552cc1f9cda13e0522fafb0dbac8/kubernetes/client/api_client.py#L239).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]