bolkedebruin commented on code in PR #51059:
URL: https://github.com/apache/airflow/pull/51059#discussion_r2149221499


##########
airflow-core/src/airflow/serialization/serde.py:
##########
@@ -145,6 +167,12 @@ def serialize(o: object, depth: int = 0) -> U | None:
         qn = "builtins.tuple"
         classname = qn
 
+    if _is_pydantic_model(o):
+        # to match the generic Pydantic serializer and deserializer in 
_serializers and _deserializers
+        qn = "pydantic.main.BaseModel"

Review Comment:
   I'd prefer this as a constant



##########
airflow-core/src/airflow/serialization/serde.py:
##########
@@ -68,6 +68,28 @@
 _builtin_collections = (frozenset, list, set, tuple)  # dict is treated 
specially.
 
 
+def _is_namedtuple(cls: Any) -> bool:
+    """
+    Return True if the class is a namedtuple.
+
+    Checking is done by attributes as it is significantly faster than
+    using isinstance.
+    """
+    return hasattr(cls, "_asdict") and hasattr(cls, "_fields") and 
hasattr(cls, "_field_defaults")
+
+
+def _is_pydantic_model(cls: Any) -> bool:

Review Comment:
   Please move this below to group them with the other private methods



##########
airflow-core/src/airflow/serialization/serializers/pydantic.py:
##########
@@ -0,0 +1,80 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, Any, cast
+
+from airflow.serialization.serde import _is_pydantic_model

Review Comment:
   You are importing a private method from a dynamically loaded module. I don't 
we should do that. Also it looks a bit risky / weird from a circular dependency 
point of view. 



##########
airflow-core/src/airflow/serialization/serde.py:
##########
@@ -68,6 +68,28 @@
 _builtin_collections = (frozenset, list, set, tuple)  # dict is treated 
specially.
 
 
+def _is_namedtuple(cls: Any) -> bool:

Review Comment:
   Please move these to group them with the other private methods



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