amoghrajesh commented on code in PR #77523:
URL: https://github.com/apache/airflow/pull/77523#discussion_r4678564287
##########
task-sdk/src/airflow/sdk/serde/serializers/kubernetes.py:
##########
@@ -55,10 +60,46 @@ def safe_get_name(pod):
return None
try:
- return PodGenerator.serialize_pod(o), qualname(o), __version__,
True
+ return ApiClient().sanitize_for_serialization(o), qualname(o),
__version__, True
except Exception:
log.warning("Serialization failed for pod %s", safe_get_name(o))
log.debug("traceback for serialization error", exc_info=True)
return "", "", 0, False
return "", "", 0, False
+
+
+def deserialize(cls: type, version: int, data: dict) -> Any:
+ if version > __version__:
+ raise TypeError(f"serialized version {version} is newer than class
version {__version__}")
+
+ if not is_pydantic_model(cls):
+ raise TypeError(f"do not know how to deserialize {qualname(cls)}")
+ model = cast("type[pydantic.BaseModel]", cls)
+
+ try:
+ return model.model_validate(data)
Review Comment:
Unknown fields are now dropped on the retry, so old pods with fields removed
in 37 still load. Added a test.
##########
task-sdk/tests/task_sdk/serde/test_serde.py:
##########
@@ -335,6 +336,15 @@ def test_serder_dataclass(self):
d = deserialize(e)
assert i.x == getattr(d, "x", None)
+ def test_kubernetes_pod_with_legacy_values(self):
+ encoded = {
+ CLASSNAME: qualname(k8s.V1Pod),
+ VERSION: 1,
+ DATA: {"metadata": {"name": "foo", "labels": {"a": 1}}},
+ }
+
+ assert deserialize(encoded) ==
k8s.V1Pod(metadata=k8s.V1ObjectMeta(name="foo", labels={"a": "1"}))
Review Comment:
Added.
--
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]