Skip to content

Lazy-load Alembic in db_manager imports#65655

Draft
hkc-8010 wants to merge 1 commit intoapache:mainfrom
hkc-8010:fix/reduce-alembic-import-noise
Draft

Lazy-load Alembic in db_manager imports#65655
hkc-8010 wants to merge 1 commit intoapache:mainfrom
hkc-8010:fix/reduce-alembic-import-noise

Conversation

@hkc-8010
Copy link
Copy Markdown

What this PR does

Avoids eagerly importing Alembic when airflow.utils.db / airflow.utils.db_manager are imported.

Today, airflow.utils.db_manager imports from alembic import command at module import time. Because airflow.utils.db imports RunDBManager, that path loads Alembic during a normal import and emits the noisy alembic.runtime.plugins INFO lines like:

setup plugin alembic.autogenerate.schemas
setup plugin alembic.autogenerate.tables
setup plugin alembic.autogenerate.types
setup plugin alembic.autogenerate.constraints
setup plugin alembic.autogenerate.defaults
setup plugin alembic.autogenerate.comments

This PR defers importing alembic.command until the DB migration operations actually need it.

Why

This keeps normal Airflow imports quiet without suppressing logs globally and without changing Alembic behavior during real migration operations.

Related issue

Closes #65652

Testing

  • pytest airflow-core/tests/unit/utils/test_db_manager.py -q
  • Breeze Python 3.13 / Postgres:
    • python -m pytest tests/unit/utils/test_db_manager.py -q
  • Verified the original repro is clean in Breeze:
    • import airflow.utils.db_manager
    • import airflow.utils.db

@hkc-8010
Copy link
Copy Markdown
Author

A bit of extra validation context from local repro/testing:

  • I reproduced the noisy alembic.runtime.plugins output in OSS Airflow 3.2.0, not just in Astro Runtime.
  • In OSS, plain import airflow stayed clean in my tests, but these import paths emitted the setup plugin alembic.autogenerate.* lines:
    • import airflow.utils.db
    • import airflow.utils.db_manager
    • from airflow.utils.db_manager import RunDBManager
  • I validated the fix in Breeze with Python 3.13 + Postgres:
    • python -m pytest tests/unit/utils/test_db_manager.py -q -> 15 passed
    • import airflow.utils.db_manager -> clean
    • import airflow.utils.db -> clean

So the issue appears to be the eager Alembic import on the DB manager import path, and the lazy import in this PR removes the noise without changing the actual migration call sites.

@potiuk potiuk added ready for maintainer review Set after triaging when all criteria pass. and removed ready for maintainer review Set after triaging when all criteria pass. labels Apr 22, 2026
@potiuk potiuk marked this pull request as draft April 23, 2026 01:09
@potiuk
Copy link
Copy Markdown
Member

potiuk commented Apr 23, 2026

@hkc-8010 This PR has been converted to draft because it does not yet meet our Pull Request quality criteria.

Issues found:

  • Failing CI: Special tests / Pendulum2 test: core / All-core:Pendulum2-Postgres:14:3.10:Core...Serialization, Special tests / Latest Boto test: providers / All-prov:LatestBoto-Postgres:14:3.10:-amazon,celer...standard, Special tests / Pendulum2 test: providers / All-prov:Pendulum2-Postgres:14:3.10:-amazon,celer...standard (+9 more). Please investigate and fix.

What to do next:

  • Address the items above.
  • Make sure static checks pass locally: prek run --from-ref main --stage pre-commit.
  • Mark the PR as "Ready for review" when you are done.

Converting a PR to draft is not a rejection — it is an invitation to bring the PR up to the project's standards so that maintainer review time is spent productively. There is no rush — take your time and work at your own pace. We appreciate your contribution and are happy to wait for updates. If you have questions, feel free to ask on the Airflow Slack.


Note: This comment was drafted by an AI-assisted triage tool and may contain mistakes. Once you have addressed the points above, an Apache Airflow maintainer — a real person — will take the next look at your PR. We use this two-stage triage process so that our maintainers' limited time is spent where it matters most: the conversation with you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Importing airflow.utils.db eagerly imports Alembic and emits noisy alembic.runtime.plugins INFO logs

2 participants