The GitHub Actions job "Tests" on 
airflow.git/fix/db-clean-dag-version-fk-constraint has failed.
Run started by GitHub user Arunodoy18 (triggered by potiuk).

Head commit for run:
10119c19640e7288aa9733a47b9ed8bda7a9ac9f / Arunodoy18 <[email protected]>
Fix db clean foreign key constraint error with dag_version table

When using 'airflow db clean', an IntegrityError occurs when attempting
to delete rows from the dag_version table that are still referenced by
task_instance or dag_run rows. This happens because:

1. dag_version rows are deleted based on their 'created_at' timestamp
2. task_instance rows are deleted based on their 'start_date' timestamp
3. A DAG created long ago but run recently has an old dag_version but
   recent task_instance records
4. The foreign key constraint task_instance_dag_version_id_fkey was
   changed to ON DELETE RESTRICT in migration 3ac9e5732b1f

This fix adds logic to exclude dag_version rows from deletion if they
are still referenced by any task_instance or dag_run rows, regardless
of the age of the dag_version record itself. This respects the foreign
key constraint and prevents the IntegrityError.

Changes:
- Modified _build_query() in db_cleanup.py to add EXISTS checks for
  dag_version table, excluding rows with active references
- Added comprehensive test case to verify dag_version with active
  references is not deleted even when old enough to meet age criteria

Fixes issue where db clean fails with:
IntegrityError: Cannot delete or update a parent row: a foreign key
constraint fails (airflow.task_instance, CONSTRAINT
task_instance_dag_version_id_fkey FOREIGN KEY (dag_version_id)
REFERENCES dag_version (id) ON DELETE RESTRICT)

Report URL: https://github.com/apache/airflow/actions/runs/20406563244

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to