Skip to content

[v3-2-test] Dispose flask_sqlalchemy + airflow ORM engines in fab test fixtures (#65941)#66896

Closed
vatsrahul1001 wants to merge 1 commit into
v3-2-testfrom
backport-322-65941
Closed

[v3-2-test] Dispose flask_sqlalchemy + airflow ORM engines in fab test fixtures (#65941)#66896
vatsrahul1001 wants to merge 1 commit into
v3-2-testfrom
backport-322-65941

Conversation

@vatsrahul1001
Copy link
Copy Markdown
Contributor

@vatsrahul1001 vatsrahul1001 commented May 14, 2026

Cherry-pick of #65941


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Opus 4.7)

Generated-by: Claude Code (Opus 4.7) following the guidelines

…65941)

Flake on a Pendulum2 providers run ended with 8 fab test errors —
``psycopg2.OperationalError: ... FATAL: sorry, too many clients
already`` after 10031 tests had passed. Postgres' default
``max_connections=100`` was being exhausted before fab tests at the
end of the bucket could acquire a connection.

The accumulation came from fab test fixtures, not from per-test
session leaks:

- ``providers/fab/tests/unit/fab/www/views/conftest.py`` called
  ``settings.configure_orm()`` in an autouse module-scope fixture.
  ``configure_orm()`` reassigns the global engine **without** disposing
  the previous one, orphaning a pool of up to 15 pooled connections
  per call. ``settings.reconfigure_orm()`` is the helper that calls
  ``dispose_orm()`` first.
- Several fab ``app`` fixtures call ``application.create_app()``,
  which does ``db = SQLAlchemy(flask_app)`` — flask_sqlalchemy
  eagerly creates a per-app engine in ``init_app()``. None of the
  fixtures disposed those engines on teardown, so each Flask app's
  pool survived the fixture and accumulated for the worker's
  lifetime. The fab bucket is one worker that runs many such
  fixtures back-to-back.

Fixes:

- ``views/conftest.py``: switch to ``reconfigure_orm()`` (no leak on
  re-entry); dispose the flask_sqlalchemy engines on the
  module-scope ``app`` fixture teardown.
- ``www/test_auth.py``, ``views/test_views_custom_user_views.py``:
  add try/finally around the function-scope ``app`` fixture and
  dispose the flask_sqlalchemy engines per test.
- ``auth_manager/test_security.py``: dispose engines on the
  module-scope ``app`` fixture teardown.
- ``auth_manager/conftest.py``: convert the session-scope
  ``minimal_app_for_auth_api`` to ``yield`` and dispose engines on
  teardown.

A follow-up branch that bumped ``max_connections`` to 300 has been
dropped — with the leak fixed it's no longer load-bearing.

Failing run: https://github.com/apache/airflow/actions/runs/24976790617/job/73131061767

(cherry picked from commit eee05dd)
@vatsrahul1001 vatsrahul1001 requested a review from vincbeck as a code owner May 14, 2026 04:31
@vatsrahul1001 vatsrahul1001 added this to the Airflow 3.2.2 milestone May 14, 2026
@vatsrahul1001 vatsrahul1001 added the changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) label May 14, 2026
vincbeck
vincbeck previously approved these changes May 14, 2026
@vincbeck vincbeck dismissed their stale review May 14, 2026 13:18

This is a provider only change, no need to backport

@vincbeck
Copy link
Copy Markdown
Contributor

This is a provider change, no need to backport

@vincbeck vincbeck closed this May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers changelog:skip Changes that should be skipped from the changelog (CI, tests, etc..) provider:fab

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants