Repository navigation
Conversation
Preserve Dags while task instances still reference them so cascading version deletion cannot violate task instance foreign keys. Reuse the existing reference guard during candidate selection and deletion.
1 of 2 tasks
Contributor
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
airflow db cleancan fail when cleaning up a stale Dag with task instances that have never started.For example, manually triggering a paused Dag can leave a queued Dag run and task instances with NULL start dates. If the Dag file is subsequently removed and the Dag becomes eligible for cleanup, the following can happen:
start_dateis NULL.last_parsed_time.dag_versionrows, including versions still referenced by the surviving task instances.Protecting referenced versions during
dag_versioncleanup alone is insufficient because deleting the parent Dag can still cascade to those versions.This change reuses the existing
skip_if_referencedmechanism withtask_instance.dag_idto exclude Dags that still have task instances. The reference check applies both when selecting cleanup candidates and immediately before deletion. Dags without surviving task instances remain eligible for cleanup.Regression tests verify that:
All five new test cases fail with a foreign-key constraint violation without the fix.
This PR addresses the cleanup failure in #71864. Deleting records with NULL start dates is a separate change tracked in #69872 and discussed in #69879.
closes: #71864
Validation
test_db_cleanup.py: PostgreSQL 120 passed, MySQL 119 passed, SQLite 118 passed, with backend-specific skips.apache-airflowdocumentation build passed.Was generative AI tooling used to co-author this PR?
Generated-by: Codex (GPT-6) following the guidelines