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

   `DAG.test()` re-walks the whole bundle that owns the tested Dag on every 
call: #66205 added that so Dags triggered through `TriggerDagRunOperator` exist 
in the metadata DB even when the parent was serialized earlier (#64884). The 
cost is that debugging one Dag parses and re-syncs every Dag file in the bundle 
each time, which is what #72513 reports.
   
   This keeps the guarantee from #66205 but narrows the work in the common 
case. Within the owning bundle, `DAG.test()` now parses only the file that 
defines the tested Dag plus the files of the Dags it triggers, when those files 
are known. It still walks the whole bundle when they are not:
   
   - the tested Dag is not defined inside the bundle
   - a trigger target is not resolvable before runtime (a templated 
`trigger_dag_id`, an XComArg, or a mapped operator expanding over it)
   - a target has never been parsed, so the metadata DB does not know which 
file defines it (the #64884 case)
   
   Trigger targets are found through the `trigger_dag_id` template field rather 
than the operator class, so the Task SDK does not import the standard provider. 
The bundle-selection logic (owning bundle first, all bundles as fallback) and 
the "no parsing context" rule from #66205 are unchanged.
   
   **Changes**
   
   - `task-sdk/src/airflow/sdk/definitions/dag.py`: build the `BundleDagBag` 
without collecting, parse the selected files with 
`collect_dags(dag_folder=<file>)`, fall back to the full walk when the 
selection is not possible or does not yield the tested Dag; two module-level 
helpers, `_static_trigger_targets` and `_dag_test_files_to_sync`
   - `airflow-core/tests/unit/models/test_dag.py`: 
`test_dag_test_parses_only_needed_files_once_targets_are_known` (second call 
parses one file and leaves an unrelated sibling untouched; fails on main) and 
`test_dag_test_walks_bundle_when_trigger_target_is_templated`
   
   **Testing**
   
   - `airflow-core`: `tests/unit/models/test_dag.py` (all 211 tests)
   - `task-sdk`: `tests/task_sdk/definitions/test_dag.py`
   - mypy on the changed module, prek hooks on the changed files
   
   closes: #72513
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (please specify the tool below)
   
   Generated-by: Claude Code (Claude Fable 5.1) following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions).
 I reviewed and understand all changes; the tests were run locally as listed 
above.
   
   ---
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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