wjddn279 commented on code in PR #63871:
URL: https://github.com/apache/airflow/pull/63871#discussion_r3166260701


##########
airflow-core/src/airflow/serialization/helpers.py:
##########
@@ -61,25 +65,32 @@ def translate_tuples_to_lists(obj: Any):
             return {key: translate_tuples_to_lists(value) for key, value in 
obj.items()}
         return obj
 
-    def sort_dict_recursively(obj: Any) -> Any:
-        """Recursively sort dictionaries to ensure consistent ordering."""
+    def sort_and_make_static_dict_recursively(obj: Any) -> Any:
+        """Recursively sort dictionaries and make callable value static to 
ensure consistent ordering."""
+        if callable(obj):
+            return make_callable_static(obj)
         if isinstance(obj, dict):
-            return {k: sort_dict_recursively(v) for k, v in 
sorted(obj.items())}
+            return {k: sort_and_make_static_dict_recursively(v) for k, v in 
sorted(obj.items())}
         if isinstance(obj, list):
-            return [sort_dict_recursively(item) for item in obj]
+            return [sort_and_make_static_dict_recursively(item) for item in 
obj]
         if isinstance(obj, tuple):
-            return tuple(sort_dict_recursively(item) for item in obj)
+            return tuple(sort_and_make_static_dict_recursively(item) for item 
in obj)
         return obj
 
     max_length = conf.getint("core", "max_templated_field_length")
 
     if not is_jsonable(template_field):
         try:
-            serialized = template_field.serialize()
+            # If the callable objects are in dict values, it makes is_jsonable 
False.
+            # So, exclude dicts here; they are handled separately in the logic 
below.
+            if isinstance(template_field, dict):
+                template_field = 
sort_and_make_static_dict_recursively(template_field)
+                serialized = str(template_field)

Review Comment:
   if `str()`is not applied to `serialized` out of dict
   
   ```
   /usr/python/lib/python3.10/site-packages/sqlalchemy/orm/state.py:596: in 
_initialize_instance
       with util.safe_reraise():
   /usr/python/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py:121: 
in __exit__
       raise exc_value.with_traceback(exc_tb)
   /usr/python/lib/python3.10/site-packages/sqlalchemy/orm/state.py:594: in 
_initialize_instance
       manager.original_init(*mixed[1:], **kwargs)
   airflow-core/src/airflow/models/serialized_dag.py:349: in __init__
       self.dag_hash = SerializedDagModel.hash(dag_data)
   airflow-core/src/airflow/models/serialized_dag.py:378: in hash
       data_json = json.dumps(data_, sort_keys=True).encode("utf-8")
   /usr/python/lib/python3.10/json/__init__.py:238: in dumps
       **kw).encode(obj)
   /usr/python/lib/python3.10/json/encoder.py:199: in encode
       chunks = self.iterencode(o, _one_shot=True)
   /usr/python/lib/python3.10/json/encoder.py:257: in iterencode
       return _iterencode(o, 0)
   /usr/python/lib/python3.10/json/encoder.py:179: in default
       raise TypeError(f'Object of type {o.__class__.__name__} '
   E   TypeError: Object of type PlainXComArg is not JSON serializable
   ```
   
   the values has object type (e.g. `PlainXComArg`) must be converted to 
`string`



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