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

   
   ## Summary
   `airflow db clean` could delete `dag_version` rows that were still 
referenced by surviving `task_instance` rows, which caused a 
`ForeignKeyViolation` during cleanup. This fix makes `dag_version` cleanup skip 
versions that are still referenced after the `task_instance` pass runs.
   
   ## Changes
   - **`airflow-core/src/airflow/utils/db_cleanup.py`** -- added a reference 
check for `dag_version` cleanup so rows still referenced by surviving task 
instances are not deleted, and included the `id` column in the cleanup table 
shape.
   - **`airflow-core/tests/unit/utils/test_db_cleanup.py`** -- added a 
regression test that creates multiple DAG versions and verifies `db clean` 
retains the referenced version while still deleting unreferenced older versions.
   
   ## Test plan
   - [x] `uv run --project airflow-core pytest 
airflow-core/tests/unit/utils/test_db_cleanup.py::TestDBCleanup::test_run_cleanup_keeps_referenced_dag_versions
 -xvs`
   - [x] `ruff check airflow-core/src/airflow/utils/db_cleanup.py 
airflow-core/tests/unit/utils/test_db_cleanup.py`
   - [x] `ruff format --check airflow-core/src/airflow/utils/db_cleanup.py 
airflow-core/tests/unit/utils/test_db_cleanup.py`
   - [ ] CI passes (ruff, mypy, pytest)
   
   Fixes #63703
   


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