Skip to content

Fix dag test trigger 404#64945

Open
Subham-KRLX wants to merge 1 commit intoapache:mainfrom
Subham-KRLX:fix-dag-test-trigger-404
Open

Fix dag test trigger 404#64945
Subham-KRLX wants to merge 1 commit intoapache:mainfrom
Subham-KRLX:fix-dag-test-trigger-404

Conversation

@Subham-KRLX
Copy link
Copy Markdown
Contributor

@Subham-KRLX Subham-KRLX commented Apr 9, 2026

This PR fixes a bug where TriggerDagRunOperator failed with a 404 Not Found error when executed via dag.test().

The issue was caused by an overly restrictive parsing context in the test() method that limited DAG synchronization to only the specific DAG being tested. This meant that any target DAGs (triggered by the test) were never synchronized to the metadata database, making them invisible to the in-process Execution API.

Changes:

Removed the _airflow_parsing_context_manager restriction from the bundle synchronization loop in dag.test().
This ensures all DAGs in the test environment's bundles are properly synchronized to the DB before execution begins.

closes: #64884

Was generative AI tooling used to co-author this PR?
Yes — Claude (For pr description)

@Subham-KRLX Subham-KRLX marked this pull request as draft April 9, 2026 07:16
@Subham-KRLX Subham-KRLX force-pushed the fix-dag-test-trigger-404 branch from 282f82e to 1181e43 Compare April 9, 2026 07:34
@Subham-KRLX Subham-KRLX marked this pull request as ready for review April 9, 2026 09:36
@kaxil kaxil requested a review from Copilot April 10, 2026 19:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes DAG.test() failing with TriggerDagRunOperator due to the in-process Execution API not finding the triggered (target) DAG in the metadata DB, by adjusting how DAG bundles are synchronized during dag.test().

Changes:

  • Remove the parsing-context restriction during bundle synchronization in DAG.test() so more DAGs are serialized/synced to the DB.
  • Add a regression test ensuring dag.test() succeeds when a DAG triggers another DAG via TriggerDagRunOperator.
  • Add a dedicated unit-test DAG file containing a parent DAG that triggers a target DAG.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
task-sdk/src/airflow/sdk/definitions/dag.py Adjusts DAG.test() bundle parsing/sync behavior to include triggered DAGs.
airflow-core/tests/unit/models/test_dag.py Adds regression test for dag.test() + TriggerDagRunOperator.
airflow-core/tests/unit/dags/test_dag_test_trigger_dagrun_operator.py Provides parent/target DAG definitions used by the new regression test.

Comment on lines 1303 to 1306
sync_bag_to_db(dagbag, bundle.name, bundle.version)
version = DagVersion.get_version(self.dag_id)
if version:
break
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bundle sync loop still breaks as soon as the current DAG’s DagVersion is found. That means bundles later in get_all_dag_bundles() will not be parsed/synced, so dag.test() can still hit the same 404 when TriggerDagRunOperator targets a DAG that lives in a different (later) bundle. If the goal is to make triggered DAGs visible to the in-process Execution API, this should continue syncing all configured bundles (or otherwise ensure the target DAG(s) are synced) rather than breaking early.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This update ensures dag.test() correctly syncs all available bundles instead of stopping early once it finds the parent DAG this fix allows TriggerDagRunOperator to work reliably across different bundles by making sure all target DAGs are materialized in the database before execution.

This fix ensures all configured bundles are synchronized during dag.test()
if the parent DAG is missing from the database. This allows
TriggerDagRunOperator to find target DAGs even if they reside in different
bundles.

Also adds a specific multi-bundle regression test to verify this scenario.

closes: apache#64884
@Subham-KRLX Subham-KRLX force-pushed the fix-dag-test-trigger-404 branch from 1181e43 to 348379b Compare April 11, 2026 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to use TriggerDagRunOperator from dag.test()

2 participants