Repository navigation
Conversation
asset_event, task_reschedule and deadline were configured to filter on a dag_id column that none of them has, so passing --dag-ids or --exclude-dag-ids made the cleanup fail on exactly those tables while the same command without a dag filter succeeded.
|
@Arose26 - Please hold on this one for a moment, and apologies for the three weeks of silence; that's on us, not on you. Your diagnosis here is the right one and I want to keep it. #66350 fixes the same crash, but for missed part that you caught. They stop the crash by removing the filter rather than fixing it, so The problem is that the two PRs are each half of a fix, and #66350 already carries the I'm adding the |
ferruzzi
left a comment
There was a problem hiding this comment.
Requesting changes as a merge guardrail. This is not a criticism of the code, @Arose26's approach here is the one that should ship and there is nothing I want changed in it.
Maintainers: please don't merge this independently. It is one half of a pair with #66350, which carries the Airflow 3.3.2 milestone. If they land separately, or if one gets backported without the other, we ship a release where --dag-ids silently over-deletes. See my comment above for details.
@Arose26 - if a triage bot follows this telling you the ball is now in your court, it isn't. Nothing is needed from you, we'll pull your fix over to that PR (with author credit, of course) and I'll close this PR once they are consolidated.
|
Folded into #66350 with your author credit preserved. Thanks for the work, and sorry again for the confusion. |
closes: #69030
airflow db cleanfails onasset_event,deadlineandtask_reschedulewhenever--dag-idsor--exclude-dag-idsis passed, while the same command without a dag filter succeeds:Cause
All three are configured with
dag_id_column_name="dag_id", and none of them has adag_idcolumn:asset_eventsource_dag_idtask_rescheduleti_id→task_instance.iddeadlinedagrun_id→dag_run.id_build_queryonly readsdag_id_columnwhen a dag filter is requested, which is why the failure appears solely with those two flags.I checked the remaining entries in
config_listagainst the table metadata rather than assuming the report was exhaustive —dag,dag_run,dag_version,job,log,task_instance,task_instance_history,task_state_storeandxcomall genuinely havedag_id. These three are the only broken ones.Change
asset_eventfilters onsource_dag_id.The other two have no dag id of their own, so
_TableConfiggainsdag_id_via=(fk_column, parent_table, parent_pk_column)and filters through the parent'sdag_id. It is built as a correlatedEXISTS, matching theskip_if_referencedguard just above it in the same function.EXISTSrather thanIN/NOT INbecausedeadline.dagrun_idis nullable. A deadline attached to no dag run belongs to no dag, so it is kept under--dag-idsand removed under--exclude-dag-ids; withNOT IN, the NULL would swallow the comparison and the row would survive a filter that does not name it. Setting bothdag_id_column_nameanddag_id_viaraises rather than silently ANDing two filters.Dry-run output prints the resolved path (
ti_id -> task_instance.dag_id) instead ofNone, which would otherwise read as "this flag does not apply to this table".Credit where it is due: #69177 was an earlier attempt at this issue and identified the same three tables before being closed by its author. This PR reaches the filter differently — a correlated
EXISTSreusing the existingskip_if_referencedidiom rather than added join metadata — and audits the rest ofconfig_listfor the same class of mistake. The review comment on that PR, asking for the parent-cascade path to be covered as well as the child's own filter, is answered by the parametrized test below.Tests
--dag-idsand under--exclude-dag-ids. This needs no fixture rows — the statement fails against the schema — and reproduces the reportedRuntimeErrorverbatim, naming the same three tables.task_rescheduleandasset_event, cleaned with--dag-ids dag1: onlydag2's rows survive. Parametrized to also run withtask_instanceanddag_runin the table list, so the path where the parents are cleaned first and cascade-delete the children is covered as well as the child's own filter. Archiving is on (the default), so the archive-and-delete path runs against the new subquery too._TableConfigguard rejecting both filter styles at once.All four cleanup cases fail before this change and pass after.
test_db_cleanup.pyandtest_db_command.pypass (177 passed, 6 skipped). Eight errors intest_db_cleanup.pyare a local environment gap —ModuleNotFoundError: No module named 'airflow_shared'raised in thecap_structlogfixture — and occur identically on an unmodified checkout.mypyandruffare clean on both files.Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code (Opus 5) following the guidelines