Skip to content

Fix airflow db clean failure with DAG filtering on joined tables - #69177

Closed
onlyarnav wants to merge 4 commits into
apache:mainfrom
onlyarnav:fix-db-clean-dag-ids
Closed

onlyarnav wants to merge 4 commits into
apache:mainfrom
onlyarnav:fix-db-clean-dag-ids

Conversation

@onlyarnav

Copy link
Copy Markdown
Member

Fix airflow db clean failure with DAG filtering on joined tables

closes: #69030

Description

When running airflow db clean with --dag-ids or --exclude-dag-ids, the command previously failed with a RuntimeError on the asset_event, deadline, and task_reschedule tables.

This occurred because the _TableConfig for these tables incorrectly declared dag_id_column_name="dag_id", but these tables either do not have a dag_id column or require a JOIN to resolve it.

Changes made in this PR:

  • asset_event: Mapped the correct column by changing it to dag_id_column_name="source_dag_id".
  • deadline: Removed the dag_id column mapping and added dag_id_join_info to JOIN the dag_run table and filter by dag_run.dag_id.
  • task_reschedule: Removed the dag_id column mapping and added dag_id_join_info to JOIN the task_instance table and filter by task_instance.dag_id.
  • Added a new unit test test_cleanup_with_dag_id_filtering_for_joined_tables to explicitly verify the SQL generation and JOIN logic for these tables.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)
    Claude Code (Opus 4.8)

@onlyarnav
onlyarnav requested a review from phanikumv July 1, 2026 06:04
@potiuk potiuk added the ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green. label Jul 2, 2026
When running \�irflow db clean\ with \--dag-ids\ or \--exclude-dag-ids\, the command fails on the \�sset_event\, \deadline\, and \	ask_reschedule\ tables. This occurs because the \_TableConfig\ for these tables declared \dag_id_column_name=\dag_id\, but these tables either do not have a \dag_id\ column or require a JOIN to resolve it.

This change maps the correct column for \�sset_event\ and adds a join lookup for \deadline\ and \	ask_reschedule\ so they can be filtered properly without encountering SQL errors.
This ensures that the cascade-deletion behavior is covered, as a full \�irflow db clean\ run cleans base tables first, which cascade-deletes the child rows before their own dag-filter logic executes.
@onlyarnav onlyarnav closed this by deleting the head repository Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for maintainer review Set by triage when all criteria pass, or by the fork CI reconciler when fork CI is green.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

airflow db clean fails with --dag-ids / --exclude-dag-ids

3 participants