meel-ayush opened a new pull request, #76556:
URL: https://github.com/apache/airflow/pull/76556

   
   ### Description
   
   Closes: #76552
   
   In Airflow 3, `dag_id` serves as the primary key of `DagModel` across all 
configured DAG bundles. When multiple bundles inadvertently declare a Dag with 
the same `dag_id`, parsing the secondary bundle unconditionally overwrote 
`DagModel.bundle_name` and `DagModel.relative_fileloc`.
   
   If the primary bundle had active DagRuns or queued tasks, this caused 
split-brain execution payloads: `workload.bundle_info.version` preserved the 
primary commit SHA while `workload.bundle_info.name` pointed to the secondary 
bundle. Consequently, workers crashed with `AirflowException: Version '<sha>' 
not found in repository for bundle '<secondary>'`, and multi-team token 
authentication failed with HTTP 403 Forbidden.
   
   This PR introduces cross-bundle collision rejection during parse collection:
   - `_reject_cross_bundle_dag_id_collisions` drops incoming Dags whose 
`dag_id` is already registered by another active bundle, preserving the 
existing `DagModel` row.
   - Records a clear user-facing import error on the offending file: `DAG 
'<dag_id>' is already registered in bundle '<existing_bundle>' 
(<existing_fileloc>). DAG IDs must be unique across all bundles.`
   - Permits adoption of a `dag_id` when the previous bundle's Dag has been 
deleted and marked stale (`is_stale == True`).
   - Defends lower-level `DagModelOperation.update_dags` against overwriting 
active foreign-bundle records.
   
   ### Tests
   
   - Unit tests added in 
`airflow-core/tests/unit/dag_processing/test_collection.py` 
(`TestRejectCrossBundleDagIdCollisions`) verifying cross-bundle collision 
rejection, error message recording, preservation of existing `DagModel` 
records, selective batch filtering, and stale Dag adoption.
   
   ### AI Usage
   
   - [ ] Yes (please specify the tool below)


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