Skip to content

Fix external DB manager upgrades with existing tables#66674

Merged
jscheffl merged 7 commits into
apache:mainfrom
anmolxlight:fix/external-db-manager-preexisting-tables
May 13, 2026
Merged

Fix external DB manager upgrades with existing tables#66674
jscheffl merged 7 commits into
apache:mainfrom
anmolxlight:fix/external-db-manager-preexisting-tables

Conversation

@anmolxlight
Copy link
Copy Markdown
Contributor

What

Fixes external DB manager upgrades when manager-owned tables already exist but the manager-specific Alembic version table does not.

Previously, BaseDBManager.upgradedb() treated that state as an empty database, called create_db_from_orm(), and stamped the manager to head. Because metadata.create_all() is a no-op for existing tables, migration bodies were skipped while Alembic believed the schema was current.

Why

This breaks upgrades such as Airflow 3.1 + edge3 1.x to Airflow 3.2 + edge3 3.4, where edge_job, edge_worker, and edge_logs already exist from the pre-EdgeDBManager era, but alembic_version_edge3 does not. The old path stamped edge3 to head without applying migrations that add columns like edge_worker.concurrency and edge_job.team_name.

How

  • Detect existing manager-owned tables before falling back to ORM creation in BaseDBManager.upgradedb().
  • If tables exist with no manager revision, stamp the manager to its base revision, then run Alembic upgrade to heads.
  • Apply the same behavior to FABDBManager.upgradedb(), which has its own upgrade implementation.
  • Add generic BaseDBManager tests plus edge3 and FAB coverage.

Tests

  • uv run ruff check airflow-core/src/airflow/utils/db_manager.py airflow-core/tests/unit/utils/test_db_manager.py providers/edge3/tests/unit/edge3/models/test_db.py providers/fab/src/airflow/providers/fab/auth_manager/models/db.py providers/fab/tests/unit/fab/auth_manager/models/test_db.py
  • uv run --project airflow-core pytest airflow-core/tests/unit/utils/test_db_manager.py -q
  • uv run --project providers/edge3 pytest providers/edge3/tests/unit/edge3/models/test_db.py -q
  • uv run --project providers/fab pytest providers/fab/tests/unit/fab/auth_manager/models/test_db.py -q

Fixes: #66524

@boring-cyborg boring-cyborg Bot added area:providers provider:edge Edge Executor / Worker (AIP-69) / edge3 provider:fab labels May 10, 2026
@anmolxlight anmolxlight force-pushed the fix/external-db-manager-preexisting-tables branch from 3ec0bcd to 901b519 Compare May 11, 2026 05:12
Comment thread providers/edge3/src/airflow/providers/edge3/models/db.py Outdated
Copy link
Copy Markdown
Contributor

@vincbeck vincbeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but I'd like to have @jscheffl approval as well

Comment thread airflow-core/src/airflow/utils/db_manager.py
Comment thread providers/edge3/src/airflow/providers/edge3/models/db.py Outdated
Comment thread providers/edge3/src/airflow/providers/edge3/models/db.py Outdated
Comment thread providers/edge3/tests/unit/edge3/models/test_db.py
Copy link
Copy Markdown
Contributor

@jscheffl jscheffl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general GOOD! Thanks for the fix - actually ran into the same myself but had no time in discovering the root. But now seeing the PR this is opening my eyes!

Can you fix the nit?
Any maybe would be good to split the PRs such that we can make the airflow-core diff as backport into Airflow 3.2.2

Comment thread airflow-core/src/airflow/utils/db_manager.py
@jscheffl jscheffl added type:bug-fix Changelog: Bug Fixes backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch and removed area:providers provider:fab provider:edge Edge Executor / Worker (AIP-69) / edge3 labels May 13, 2026
@jscheffl jscheffl merged commit 671dd4c into apache:main May 13, 2026
142 checks passed
@github-actions github-actions Bot added this to the Airflow 3.2.3 milestone May 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Hi maintainer, this PR was merged without a milestone set.
We've automatically set the milestone to Airflow 3.2.3 based on: backport label targeting v3-2-test
If this milestone is not correct, please update it to the appropriate milestone.

This comment was generated by Milestone Tag Assistant.

@jscheffl
Copy link
Copy Markdown
Contributor

@anmolxlight thanks for the patch!

As I requested to remove Providers I am not able to back-port such that it can get into 3.2.2. Are you planning to revamp another PR with the earlier proposed changes in providers? Would be great! (Alternatively I could but would leave the credit rather to you :-D)

@jscheffl jscheffl modified the milestones: Airflow 3.2.3, Airflow 3.2.2 May 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Backport successfully created: v3-2-test

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
v3-2-test PR Link

@anmolxlight
Copy link
Copy Markdown
Contributor Author

Yes, I will open a separate provider-only PR restoring the edge3/FAB compatibility changes that were removed here. I will keep it scoped to providers and reference this PR for the core behavior.

@anmolxlight
Copy link
Copy Markdown
Contributor Author

Opened the provider-only follow-up here: #66883. It restores the Edge3/FAB compatibility path only, with regression coverage for the existing-provider-tables/no-Alembic-version case.

jscheffl pushed a commit that referenced this pull request May 13, 2026
…6674) (#66882)

* Fix external DB manager upgrades with existing tables

* Fix provider db manager upgrade compatibility

* Add provider DB manager compatibility comments

* Clarify provider DB manager cleanup version

* Fix Kafka trigger sync executor contention

* Stabilize Kafka message queue trigger test

* fix: narrow db manager fix to core

---------
(cherry picked from commit 671dd4c)

Co-authored-by: Anmol Mishra <anmolxlight@gmail.com>
Co-authored-by: Anmol Mishra <anmolx.work@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request May 20, 2026
…6674) (#66882)

* Fix external DB manager upgrades with existing tables

* Fix provider db manager upgrade compatibility

* Add provider DB manager compatibility comments

* Clarify provider DB manager cleanup version

* Fix Kafka trigger sync executor contention

* Stabilize Kafka message queue trigger test

* fix: narrow db manager fix to core

---------
(cherry picked from commit 671dd4c)

Co-authored-by: Anmol Mishra <anmolxlight@gmail.com>
Co-authored-by: Anmol Mishra <anmolx.work@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request May 20, 2026
…6674) (#66882)

* Fix external DB manager upgrades with existing tables

* Fix provider db manager upgrade compatibility

* Add provider DB manager compatibility comments

* Clarify provider DB manager cleanup version

* Fix Kafka trigger sync executor contention

* Stabilize Kafka message queue trigger test

* fix: narrow db manager fix to core

---------
(cherry picked from commit 671dd4c)

Co-authored-by: Anmol Mishra <anmolxlight@gmail.com>
Co-authored-by: Anmol Mishra <anmolx.work@gmail.com>
vatsrahul1001 pushed a commit that referenced this pull request May 21, 2026
…6674) (#66882)

* Fix external DB manager upgrades with existing tables

* Fix provider db manager upgrade compatibility

* Add provider DB manager compatibility comments

* Clarify provider DB manager cleanup version

* Fix Kafka trigger sync executor contention

* Stabilize Kafka message queue trigger test

* fix: narrow db manager fix to core

---------
(cherry picked from commit 671dd4c)

Co-authored-by: Anmol Mishra <anmolxlight@gmail.com>
Co-authored-by: Anmol Mishra <anmolx.work@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

edge3: upgrade from 1.x silently leaves schema stale — BaseDBManager.upgradedb stamps alembic_version_edge3 to head without running migrations

4 participants