fix(db_cleanup): handle NULL start_date in dag_run cleanup#69879
fix(db_cleanup): handle NULL start_date in dag_run cleanup#69879bileyroy 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
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
| extra_filters: list[Any] | None = None, | ||
| skip_if_referenced: list[tuple[str, str]] | None = None, | ||
| referenced_pk_column: str = "id", | ||
| fallback_recency_column=None, |
There was a problem hiding this comment.
This has been never passed from the caller. I see the enitre logic coupled with this field and the boolean asked to user. If you check below comment where it called, you will see we only pass the user input one.
Even this is calculated in inner parts, it should only exists where it is needed and calculated.
| skip_archive=skip_archive, | ||
| session=session, | ||
| batch_size=batch_size, | ||
| fallback_cleanup_on_null=fallback_cleanup_on_null, |
There was a problem hiding this comment.
Here we are not pssing the other new recency one
|
Thanks for your first PR! |
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):