aniketwaghh commented on code in PR #72637:
URL: https://github.com/apache/airflow/pull/72637#discussion_r3964501148


##########
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:
   You're right, and I checked it rather than taking my own word: making the 
guard reject `version >= 1` fails 17 existing tests, 
`test_deserialize_datetime_v1` and `test_datetime` among them. Dropped the 
redundant test in the same commit.



-- 
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]

Reply via email to