uranusjr commented on code in PR #31565:
URL: https://github.com/apache/airflow/pull/31565#discussion_r1206438273
##########
airflow/serialization/serde.py:
##########
@@ -302,6 +308,11 @@ def _stringify(classname: str, version: int, value: T |
None) -> str:
return s
+def _is_pydantic(cls: Any) -> bool:
+ """Return True if the class is a pydantic model."""
+ return hasattr(cls, "validate") and hasattr(cls, "json") and hasattr(cls,
"dict")
Review Comment:
How about using `isinstance` _after_ the attribute checks? The problem I
have with the current check is those attribute names are quite common and can
easily hit false positives. If we check the attributes first, the probability
of the object passed to `isinstance` is a Pydantic model should be high, and
since Pydantic models mostly inherit from BaseModel directly, the talk should
end very quickly (only two steps).
--
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]