amoghrajesh commented on code in PR #56758:
URL: https://github.com/apache/airflow/pull/56758#discussion_r2459116853


##########
airflow-core/src/airflow/serialization/typing.py:
##########
@@ -17,6 +17,7 @@
 # under the License.
 from __future__ import annotations
 
+from dataclasses import is_dataclass

Review Comment:
   ```suggestion
   ```



##########
airflow-core/src/airflow/serialization/typing.py:
##########
@@ -29,4 +30,9 @@ def is_pydantic_model(cls: Any) -> bool:
     """
     # __pydantic_fields__ is always present on Pydantic V2 models and is a 
dict[str, FieldInfo]
     # __pydantic_validator__ is an internal validator object, always set after 
model build
-    return hasattr(cls, "__pydantic_fields__") and hasattr(cls, 
"__pydantic_validator__")
+    # Check if it is not a dataclass to prevent detecting pydantic dataclasses 
as pydantic models

Review Comment:
   ```suggestion
       # Check if it is not a dataclass to prevent detecting pydantic 
dataclasses as pydantic models
       from dataclasses import is_dataclass
   ```



##########
airflow-core/tests/unit/serialization/test_serde.py:
##########
@@ -308,6 +316,17 @@ def test_serder_dataclass(self):
         d = deserialize(e)
         assert i.x == getattr(d, "x", None)
 
+    def test_serder_pydantic_dataclass(self):
+        orig = PydanticDataclass(a=5, b="SerDe Pydantic Dataclass Test")
+        serialized = serialize(orig)
+        assert orig.__version__ == serialized[VERSION]
+        assert qualname(orig) == serialized[CLASSNAME]
+        assert serialized[DATA]
+
+        decoded = deserialize(serialized)
+        assert orig.a == getattr(decoded, "a", None)
+        assert orig.b == getattr(decoded, "b", None)

Review Comment:
   nit: move this test to: 
airflow-core/tests/unit/serialization/serializers/test_serializers.py instead. 
Similar tests exist there



##########
airflow-core/tests/unit/serialization/test_serde.py:
##########
@@ -308,6 +316,17 @@ def test_serder_dataclass(self):
         d = deserialize(e)
         assert i.x == getattr(d, "x", None)
 
+    def test_serder_pydantic_dataclass(self):
+        orig = PydanticDataclass(a=5, b="SerDe Pydantic Dataclass Test")
+        serialized = serialize(orig)
+        assert orig.__version__ == serialized[VERSION]
+        assert qualname(orig) == serialized[CLASSNAME]
+        assert serialized[DATA]
+
+        decoded = deserialize(serialized)
+        assert orig.a == getattr(decoded, "a", None)
+        assert orig.b == getattr(decoded, "b", None)

Review Comment:
   ```suggestion
           assert decoded.a == orig.a
           assert decoded.b == orig.b
   ```
   
   dataclasses support equality



##########
airflow-core/src/airflow/serialization/typing.py:
##########
@@ -29,4 +30,9 @@ def is_pydantic_model(cls: Any) -> bool:
     """
     # __pydantic_fields__ is always present on Pydantic V2 models and is a 
dict[str, FieldInfo]
     # __pydantic_validator__ is an internal validator object, always set after 
model build
-    return hasattr(cls, "__pydantic_fields__") and hasattr(cls, 
"__pydantic_validator__")
+    # Check if it is not a dataclass to prevent detecting pydantic dataclasses 
as pydantic models

Review Comment:
   Importing where it is needed



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