Repository navigation
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
bugraoz93
left a comment
There was a problem hiding this comment.
I didn't quite understand why we have recency column from the implementation itself while we are always having it null on the _cleanup_table
|
Thanks for your first PR! |
airflow db clean skipping dag_run records with NULL start_date
| recency_column_name="start_date", | ||
| dag_id_column_name="dag_id", | ||
| extra_columns=["dag_id", "run_type"], | ||
| extra_columns=["dag_id", "run_type", "created_at"], |
There was a problem hiding this comment.
Since created_at was only added in 3.2.0, we probably need more columns for this. Otherwise the oldest dag runs will never be able to be selected by the query, which is the opposite of what we want.
|
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. |
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):