mohitgurav20 commented on code in PR #76859:
URL: https://github.com/apache/airflow/pull/76859#discussion_r4537128530


##########
airflow-core/src/airflow/serialization/serialized_objects.py:
##########
@@ -1966,6 +1975,39 @@ def get_dag_optional_fields_from_schema(cls) -> set[str]:
         optional_fields = operator_fields - required_fields
         return optional_fields
 
+    @classmethod
+    def _serialize_user_defined_macros(cls, dag_id: str, macros: dict) -> dict:
+        """
+        Return the JSON-safe entries from *macros*, dropping callables with a 
warning.
+
+        Only ``str``, ``int``, ``float``, ``bool``, ``None``, ``list``, and 
``dict``
+        values (recursively composed of the same types) survive serialization.
+        Any callable is skipped — the triggerer cannot reconstruct it from 
stored
+        JSON, so DAG authors who need callable macros in a trigger context 
must load
+        the bundle and re-import the DAG file instead.
+        """
+        import json as _json
+
+        safe: dict = {}
+        dropped: list[str] = []
+        for key, value in macros.items():
+            if callable(value):
+                dropped.append(key)
+                continue
+            try:
+                _json.dumps(value)
+                safe[key] = value
+            except (TypeError, ValueError):
+                dropped.append(key)
+        if dropped:
+            log.warning(

Review Comment:
   Done  switched to log.debug. You're right, this fires on every scheduler 
parse cycle, not just for triggerer-bound DAGs. Debug is the right level for a 
serialization detail.



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