mohitgurav20 opened a new pull request, #76859:
URL: https://github.com/apache/airflow/pull/76859

   ## What
   
   When tasks run with `start_from_trigger=True`, the triggerer reconstructs 
tasks directly from `SerializedDAG` instead of reloading the full DAG bundle 
from disk. Currently, `user_defined_macros` aren't preserved during DAG 
serialization, so any templated field trying to use custom macros fails during 
rendering in the triggerer context. Also, `SerializedDAG` was missing 
`get_template_env()`, which the triggerer's templater expects to call.
   
   This PR preserves JSON-safe primitive macros (strings, numbers, booleans, 
dicts, lists) through DAG serialization:
   - Added `user_defined_macros` to `schema.json` under the `dag` definition.
   - Added `user_defined_macros` field and `get_template_env()` to 
`SerializedDAG` so the triggerer can construct the Jinja environment with the 
restored values.
   - In `DagSerialization`, primitive values are kept while callables are 
safely dropped with a `WARNING` log naming the skipped keys. 
`user_defined_filters` are strictly callables by design and remain excluded.
   - Added unit tests in `test_dag_serialization.py` covering round-trip 
serialization of primitives, callable dropping with log verification, and clean 
omission when no macros are defined.
   
   ## Why
   
   In Airflow 3, triggerer-based task execution avoids re-parsing DAG files for 
performance and isolation. Without serializing `user_defined_macros`, any DAG 
relying on static configuration macros in templated fields breaks when starting 
from trigger.
   
   ## How I verified it
   
   - Verified schema validation and test suite locally:
     `uv run --project airflow-core pytest 
airflow-core/tests/unit/serialization/test_dag_serialization.py -k 
"user_defined_macros or omits_key" -v`
   - Verified Ruff formatting and lint rules:
     `ruff check --line-length 110` (All checks passed)
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (used Antigravity for drafting test cases and typing checks)
   
   Generated-by: Antigravity following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
   
   closes: #76808


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