{{ message }}
Conversation
The cleanup config named a dag_id column on three tables that do not have one. task_reschedule.dag_id was dropped in 3.0.0, deadline.dag_id in 3.1.0, and asset_event has only ever had source_dag_id. Any run passing --dag-ids or --exclude-dag-ids built SQL against a column that does not exist, and run_cleanup suppresses a failing table into a warning, so the command reported success and exited 0 while never purging a row from any of them. deadline and task_reschedule now reach their Dag the way the schema does, through dag_run and task_instance, so a table with no dag id of its own can be scoped through a foreign key. Dropping the filter instead would have been worse for deadline: it is cleaned as a dependent of dag_run precisely so its rows are archived before the ON DELETE CASCADE removes them, so an unscoped pass would purge deadlines belonging to the very Dags whose runs --exclude-dag-ids preserves. --exclude-dag-ids now also treats a NULL dag id as eligible. A row attributed to no Dag is not one of the excluded Dags' rows, but NOT IN alone yields NULL for it and retains it forever. That was every job row, since core never sets Job.dag_id, and it becomes reachable for asset_event and log too. The guard test only ever called run_cleanup without Dag filters, which is the branch that dereferences these column names, so all three configs drifted unnoticed across two releases. It is now parametrized over the filter combinations and fails on each of them.
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.

Follow-up to #70923, which restored the coverage check for
db clean. That check compares table names against the config, not the columns the config names, so it cannot catch this.airflow db clean --dag-idsor--exclude-dag-idssilently purges nothing from three tables. Each names adag_idcolumn it does not have:task_reschedule.dag_idwas dropped in 3.0.0,deadline.dag_idin 3.1.0, andasset_eventhas only ever hadsource_dag_id. The query fails on a missing column,run_cleanupsuppresses a failing table into a warning, and the command exits 0. An operator who always scopes by Dag has been growing those three tables forever while cleanup reported success.deadlineandtask_reschedulenow reach their Dag the way the schema does, throughdag_runandtask_instance.Why scope them rather than just drop the filter, which would be the smaller diff:
deadlineis cleaned as a dependent ofdag_runprecisely so its rows are archived before theON DELETE CASCADEremoves them. An unscoped pass would purge deadlines belonging to the very Dags whose runs--exclude-dag-idsis preserving, turning a silent no-op into silent data loss.--exclude-dag-idsnow also treats a NULL dag id as eligible. A row attributed to no Dag is not one of the excluded Dags' rows, butNOT INalone yields NULL for it and retains it forever. That is everyjobrow, since core never setsJob.dag_id, and it becomes reachable forasset_eventandlogtoo. This changes behaviour for those tables, in the direction the flag already documents.The guard test is the part that stops this recurring. It only ever called
run_cleanupwithout Dag filters, and the Dag filter is the only thing that dereferences these column names, so all three configs drifted unnoticed across two releases. It is now parametrized over the filter combinations and fails on each of them.