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

   ## Problem
   
   `airflow db clean` fails with an `IntegrityError` when deleting old `dag` 
rows. The `dag` → `dag_version` `ON DELETE CASCADE` propagates to 
`dag_version`, but `task_instance.dag_version_id` is `ON DELETE RESTRICT`, so 
the cascade fails the foreign key constraint (and, on MySQL, can leave the 
cleanup command blocked on metadata locks).
   
   PR #68339 added `skip_if_referenced` to protect the `dag_version` table's 
own cleanup query, but did not protect the `dag` → `dag_version` cascade path.
   
   ## Fix
   
   Add a new `skip_if_cascade_blocked` config option to `_TableConfig` that 
generates a correlated `NOT EXISTS` subquery across the cascade path. Apply it 
to the `dag` table config: exclude dags whose `dag_version` rows are still 
referenced by any `task_instance`.
   
   Closes #71864


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