fix: mark DAGs as stale when their bundle is removed from config #67271#67431
Open
bramhanandlingala wants to merge 1 commit into
Open
Conversation
…che#67271) When a DAG bundle is removed from `dag_bundle_config_list`, `sync_bundles_to_db` correctly sets `bundle.active = False` but never updated the associated `DagModel` rows to `is_stale = True`. This caused removed-bundle DAGs to remain visible in the UI as active workflows. Add a bulk UPDATE in the removed-bundle loop so that all DAGs belonging to the deactivated bundle are immediately marked stale, and extend the fixture teardown and add a regression test to cover this path.
vamsivasireddy-ops
approved these changes
May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a DAG bundle is removed from dag_bundle_config_list, sync_bundles_to_db logs "DAG bundle X is no longer found in config and has been disabled" and correctly sets bundle.active = False, but it never updates the associated DagModel rows to is_stale = True. As a result, the removed bundle's DAGs remain visible in the UI as functional workflows.
Root cause
In DagBundlesManager.sync_bundles_to_db (airflow-core/src/airflow/dag_processing/bundles/manager.py), the loop that handles bundles absent from config only sets bundle.active = False and cleans up import errors. There is no statement to flip DagModel.is_stale.
Changes
airflow-core/src/airflow/dag_processing/bundles/manager.py
Added update to the sqlalchemy import.
Added a local import of DagModel (alongside the existing ParseImportError local import, to avoid circular imports).
After marking a bundle inactive, execute a bulk UPDATE dag SET is_stale = true WHERE bundle_name = .
airflow-core/tests/unit/dag_processing/bundles/test_dag_bundle_manager.py
Updated the clear_db fixture to also clear DagModel rows before/after tests.
Added test_sync_bundles_to_db_marks_dags_stale_on_bundle_removal, creates a bundle, adds a non-stale DAG for it, removes the bundle from config, and asserts dag.is_stale is True.