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

   Fixes #44791
   
   ### What changes were proposed in this pull request?
   Fixed a foreign key constraint violation in the `airflow db clean` command 
that occurred when attempting to delete `dag_version` rows that are still 
referenced by active `task_instance` rows.
   
   ### Why are the changes needed?
   When running `airflow db clean` with a date that causes old `dag_version` 
rows (based on `created_at`) to be deleted while recent `task_instance` rows 
(based on `start_date`) that reference them are kept, an IntegrityError is 
raised due to the `task_instance_dag_version_id_fkey` RESTRICT constraint.
   
   The issue was that `dag_version` incorrectly listed `task_instance` in its 
`dependent_tables` configuration, suggesting a parent-child relationship that 
doesn't exist. In reality, `task_instance` has a foreign key TO `dag_version`, 
making it the referrer, not the dependent.
   
   ### How was this patch tested?
   - Added new test case 
`test_dag_version_not_deleted_when_task_instance_references_it` that reproduces 
the scenario and verifies the fix
   - The test creates an old `dag_version` and a recent `task_instance` 
referencing it, then runs cleanup to ensure no IntegrityError occurs
   
   ### Are there any user-facing changes?
   No, this is a bug fix that prevents an error. The behavior now correctly 
respects foreign key constraints.
   


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