kaxil commented on code in PR #72637:
URL: https://github.com/apache/airflow/pull/72637#discussion_r3963835864
##########
task-sdk/tests/task_sdk/serde/test_serializers.py:
##########
@@ -267,6 +268,43 @@ def test_numpy_deserialize_errors(self, klass, ver, value,
msg):
with pytest.raises(TypeError, match=msg):
deserialize(klass, ver, value)
+ @pytest.mark.parametrize(
+ ("klass", "ver", "value"),
+ [
+ pytest.param(uuid.UUID, 999,
"12345678-1234-5678-1234-567812345678", id="uuid"),
+ pytest.param(datetime.timedelta, 999, 60.0, id="timedelta"),
+ pytest.param(datetime.datetime, 999, {"timestamp": 1767268800.0,
"tz": None}, id="datetime"),
+ ],
+ )
+ def test_deserialize_rejects_a_newer_version(self, klass, ver, value):
+ """A payload written by a newer Airflow must not be read under the old
assumptions.
+
+ The framework does not check on a registered serializer's behalf:
serde dispatches
+ straight to ``_deserializers[classname].deserialize`` and its own
version guard covers
+ only the attr/dataclass fallback. uuid and datetime were the two
serializers missing it.
+ """
+ from airflow.sdk.serde import deserialize as _ # noqa: F401
Review Comment:
This import is discarded and the `noqa` only hides that, since the test
calls `mod.deserialize` directly and registration never matters. Going through
the public `deserialize({CLASSNAME: ..., VERSION: 999, DATA: value})` would
drop both this line and the `importlib` lookup, and it would cover the dispatch
the docstring describes rather than bypassing it
(`test_deserialize_datetime_v1` above takes that route).
##########
task-sdk/tests/task_sdk/serde/test_serializers.py:
##########
@@ -267,6 +268,43 @@ def test_numpy_deserialize_errors(self, klass, ver, value,
msg):
with pytest.raises(TypeError, match=msg):
deserialize(klass, ver, value)
+ @pytest.mark.parametrize(
+ ("klass", "ver", "value"),
+ [
+ pytest.param(uuid.UUID, 999,
"12345678-1234-5678-1234-567812345678", id="uuid"),
+ pytest.param(datetime.timedelta, 999, 60.0, id="timedelta"),
+ pytest.param(datetime.datetime, 999, {"timestamp": 1767268800.0,
"tz": None}, id="datetime"),
+ ],
+ )
+ def test_deserialize_rejects_a_newer_version(self, klass, ver, value):
+ """A payload written by a newer Airflow must not be read under the old
assumptions.
+
+ The framework does not check on a registered serializer's behalf:
serde dispatches
+ straight to ``_deserializers[classname].deserialize`` and its own
version guard covers
+ only the attr/dataclass fallback. uuid and datetime were the two
serializers missing it.
+ """
+ from airflow.sdk.serde import deserialize as _ # noqa: F401
+
+ module = "uuid" if klass is uuid.UUID else "datetime"
+ mod =
importlib.import_module(f"airflow.sdk.serde.serializers.{module}")
+
+ with pytest.raises(TypeError, match=r"serialized 999 of .* > \d+"):
+ mod.deserialize(klass, ver, value)
+
+ def test_deserialize_still_accepts_the_current_and_legacy_versions(self):
Review Comment:
On the "regression guard rather than a bug test" point in the description:
the existing tests already are that guard.
`test_deserialize_datetime_v1[edt_ambiguous]` reads the v1 EDT payload and
`test_datetime` round-trips the date and timedelta cases at version 2, and both
now dispatch through the new check, so either would fail if it started
rejecting an in-use version.
--
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]