Repository navigation
Prevent DagModel split-brain from cross-bundle dag_id collisions - #76556
meel-ayush wants to merge 1 commit into
Conversation
a608b7d to
4979ec9
Compare
4979ec9 to
55fd9e6
Compare
Dropped the update_dags() change, handling it in _reject_cross_bundle_dag_id_collisions was enough and much cleaner. Updated the PR description to match. Also swapped the dag_maker check for get_configured_bundle_names(), which was what caused the DAG.test() failure in CI. Tests are passing locally now. |
55fd9e6 to
60b22ce
Compare
60b22ce to
3d4ace8
Compare
In Airflow 3, dag_id is the primary key of DagModel across all bundles. When two DAG bundles declare a Dag with the identical dag_id, parsing the secondary bundle unconditionally overwrote DagModel.bundle_name and relative_fileloc. If the primary bundle had already created scheduled DagRuns and queued TaskInstances, the scheduler subsequently generated execution workloads with the primary bundle's commit version but the secondary bundle's name. This caused workers to crash when attempting to check out the primary commit from the secondary repository, and caused the Execution API to reject worker JWT tokens under multi-team isolation. Resolve this by rejecting incoming Dags whose dag_id is already registered by another active bundle during database collection, logging a warning and recording a user-facing parse import error stating that DAG IDs must be unique across all bundles. Stale Dags remain eligible for adoption if decommissioned from their original bundle, and internal DAG renames within the same bundle continue to function normally.
3d4ace8 to
e5237d1
Compare
|
@amoghrajesh Following up on your comment in #76551, CI is green here implementing the collision check. A user in #77241 just reported this in production on 3.4.0, so ready for review whenever you have a moment. |
Dev-iL
left a comment
There was a problem hiding this comment.
Currently (or at least on 2.11), if there are multiple dags with the same dag_id, one of them is selected at random. Assuming this is the case in 3.x, it means the behavior for bundles becomes different - one of dags is parsed and the other errors.
While this turns a runtime error into a parsing error (which is good imho), it departs from the expected behavior. I wonder - would it make more sense to internally qualify dag_ids with the bundle identifier so that collisions are avoided, and either raise a warning or treat this as an acceptable scenario?
Imagine two independent bundles, possibly belonging to different teams, each having a "load_data" id - each one does (and perhaps should) not know/care about the other. Making one of them fail parsing means the solution is possibly upstream of what the Airflow administrator has control over.
To me, it makes more sense to find a way for such dags to work side by side rather than failing to import.
|
I really like this idea. Having proper DAG namespacing (or composite keys) would be a great feature for multi-team, and I'd love to team up with you and co-author an AIP or start a dev list thread to design that properly. The catch is that we can't do it inside this bugfix:
Right now, two bundles sharing a This PR is just the immediate stopgap to prevent that split-brain today. I'd be very happy to work together with you on the broader namespacing AIP after this lands. |
Description
Closes: #76551
In Airflow 3,
dag_idis the primary key forDagModelacross all bundles. If two configured bundles define a Dag with the samedag_id, parsing the second bundle overwroteDagModel.bundle_nameandrelative_fileloc.When the first bundle had active DagRuns or queued tasks, workers received tasks with the first bundle's commit SHA but the second bundle's name, failing with
Version '<sha>' not found in repository for bundle '<secondary>'(or HTTP 403 under multi-team isolation).Changes in this PR:
_reject_cross_bundle_dag_id_collisionsif theirdag_idis already registered by another actively configured bundle, keeping the existingDagModelrow intact.get_configured_bundle_names()).Tests
TestRejectCrossBundleDagIdCollisionsinairflow-core/tests/unit/dag_processing/test_collection.pycovering duplicate rejection, batch filtering, stale Dag adoption, and adoption from unconfigured/ghost bundles.AI Usage