fix(db_cleanup): handle NULL start_date in dag_run cleanup#69879
Open
bileyroy wants to merge 1 commit into
Open
fix(db_cleanup): handle NULL start_date in dag_run cleanup#69879bileyroy wants to merge 1 commit into
bileyroy wants to merge 1 commit into
Conversation
|
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide
|
When start_date is NULL (e.g. runs that failed or were killed before execution began), the WHERE condition start_date < cutoff evaluates to NULL and silently skips these rows forever. Add --fallback-cleanup-on-null CLI flag that uses COALESCE(start_date, created_at) in the WHERE condition, keep_last subquery, and JOIN so that NULL start_date rows are cleaned based on their created_at timestamp while the most recent run per dag is still protected by keep_last. closes: apache#69872
f173ee5 to
9ad7c67
Compare
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.
closes: #69872
Summary
When
start_dateis NULL (e.g. dag_runs that were marked failed before execution began), the cleanup query'sWHERE start_date < cutoffevaluates to NULL and silently skips these rows forever.Changes
fallback_recency_column_namefield to_TableConfig(set tocreated_atfordag_run)--fallback-cleanup-on-nullCLI flag (opt-in, off by default)COALESCE(start_date, created_at)to:start_daterows are foundkeep_lastsubquery (MAX): so the latest run is correctly identified via fallbackkeep_lastJOIN condition: so the latest run is properly protectedkeep_lastprotectionTest plan
pytest airflow-core/tests/unit/utils/test_db_cleanup.py -xvs— all passedruff check/ruff format— cleanmypy— cleanairflow standaloneTesting with manual runs (keep_last not applicable):
Testing with backfill runs (keep_last applicable)
All 3 backfill runs have
start_date = NULL. With--fallback-cleanup-on-null, only 2 rows are returned for deletion, the newest run is correctly protected bykeep_lastviaCOALESCE(start_date, created_at):