Skip to content

[v3-3-test] Fix airflow db clean never purging the callback table (#70923) - #72899

Merged
vatsrahul1001 merged 1 commit into
apache:v3-3-testfrom
steveahnahn:backport-70923-v3-3
Sep 11, 2026
Merged

vatsrahul1001 merged 1 commit into
apache:v3-3-testfrom
steveahnahn:backport-70923-v3-3

Conversation

@steveahnahn

Copy link
Copy Markdown
Contributor

Backport of #70923 to v3-3-test for the Airflow 3.3.2 patch release.

The callback table was renamed from callback_request in 3.2.0 and the airflow db clean configuration was not updated with it, so a configured table that does not exist was skipped with a warning and callback rows were never purged. Only callbacks that can no longer run are removed; a SCHEDULED callback is purged only once no deadline references it, so unfired deadlines are kept. The sla_miss entry is dropped, orphaned partitioned_asset_key_log rows are purged, and the db clean coverage check walks the models package again instead of a stale relative path.

Source and newsfragment applied clean. The only conflict was in test_db_cleanup.py: the import lines and the appended test classes, because v3-3-test lacks tests that only exist on main. Resolved by adding exactly the tests from the original commit; the sqlalchemy import line keeps only the names v3-3-test uses.

(cherry picked from commit 478745a)


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

Generated-by: Claude Code (Fable 5.1) following the guidelines

* Fix airflow db clean never purging the callback table

The table was renamed from callback_request in Airflow 3.2.0 and the
cleanup configuration was not updated with it. A configured table that
does not exist is skipped with only a warning, so these rows were never
deleted and the table grew without bound, with no way for an operator to
purge it.

Only callbacks that can no longer run are removed. A callback still
awaiting execution owns its deadline row through an ON DELETE CASCADE
foreign key, so deleting one would silently drop a deadline that has not
fired yet.

The sla_miss entry is dropped as well, since that table no longer exists
in Airflow 3.

* Purge orphaned partitioned_asset_key_log rows and restore the db clean coverage check

The check that is meant to catch a metadata table being left out of
airflow db clean looked for the models package at a path relative to the
test file. That path stopped resolving when the sources moved under
airflow-core, so the check examined no models at all and its assertions
held trivially for an empty set. It has not been able to report a missing
table since, which is how the callback table went unpurged for several
releases.

Walking the package's own search path instead keeps the check working
wherever the sources live, and asserting that models were found stops it
from passing on an empty set again.

With the check restored, partitioned_asset_key_log is the one table it
reports that genuinely has no way to be purged: it carries no foreign
key, so its rows are left behind when the partition Dag run they describe
is cascade-deleted with its dag_run. Only those orphans are deleted --
rows whose partition Dag run still exists are the evidence the scheduler
evaluates to decide when that pending run fires, so they are kept
regardless of age. The other uncovered tables are recorded in the
exclusion list with the reason each is safe.

* Purge orphaned scheduled callbacks while keeping unfired deadlines in db clean

Every callback starts in SCHEDULED, a state outside both the active and the
terminal sets, and an unfired deadline's callback stays there until the deadline
is missed. Deny-listing active states would therefore purge those callbacks and,
through the ON DELETE CASCADE foreign key, silently drop deadlines that have not
fired. The finished states stay allow-listed, so an unknown state keeps its rows.
A SCHEDULED callback is purged only once no deadline references it: deleting a
Dag run cascades away its deadline at the database level, which leaves the
callback behind forever.

(cherry picked from commit 478745a)
@vatsrahul1001 vatsrahul1001 added this to the Airflow 3.3.2 milestone Sep 11, 2026
@vatsrahul1001 vatsrahul1001 added the type:bug-fix Changelog: Bug Fixes label Sep 11, 2026
@vatsrahul1001
vatsrahul1001 merged commit 16715d6 into apache:v3-3-test Sep 11, 2026
115 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants