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


##########
airflow-core/tests/unit/serialization/test_dag_serialization.py:
##########
@@ -661,6 +661,75 @@ def 
test_dag_serialization_preserves_empty_access_roles(self):
             "__var": {},
         }
 
+    @pytest.mark.db_test
+    def test_user_defined_macros_primitives_are_serialized(self):
+        """JSON-safe macro values survive a round-trip through 
DagSerialization."""
+        dag = DAG(
+            "macro_roundtrip_dag",
+            schedule=None,
+            start_date=datetime(2024, 1, 1),
+            user_defined_macros={
+                "env": "production",
+                "max_retries": 3,
+                "ratio": 0.75,
+                "flag": True,
+                "nested": {"key": "val"},
+                "items": [1, 2, 3],
+            },
+        )
+        serialized = DagSerialization.to_dict(dag)
+        DagSerialization.validate_schema(serialized)
+
+        raw_macros = serialized["dag"]["user_defined_macros"]
+        assert raw_macros["env"] == "production"
+        assert raw_macros["max_retries"] == 3
+        assert raw_macros["ratio"] == 0.75
+        assert raw_macros["flag"] is True
+        assert raw_macros["nested"] == {"key": "val"}
+        assert raw_macros["items"] == [1, 2, 3]
+
+        # Round-trip: the deserialized SerializedDAG should expose them
+        # through get_template_env() so templates render correctly.
+        ser_dag = DagSerialization.from_dict(serialized)

Review Comment:
   Done. The test now does json.dumps → json.loads before deserialization (same 
path the scheduler takes before writing to DB), and renders {{ env }}-{{ 
max_retries }} through the restored Jinja env to verify the macros are actually 
live...



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