Skip to content

Enable SQLAlchemy connection pool settings for file-based SQLite#64888

Merged
jason810496 merged 4 commits intoapache:mainfrom
jason810496:fix/sqite-sqlalchemy-pool-conf
Apr 17, 2026
Merged

Enable SQLAlchemy connection pool settings for file-based SQLite#64888
jason810496 merged 4 commits intoapache:mainfrom
jason810496:fix/sqite-sqlalchemy-pool-conf

Conversation

@jason810496
Copy link
Copy Markdown
Member

Why

SQLAlchemy 2.0+ uses QueuePool by default for file-based SQLite databases, but Airflow unconditionally skips all pool configuration (pool_size, max_overflow, pool_recycle, pool_pre_ping) for any SQLite connection — a guard that was only correct for SQLAlchemy 1.x.

What

  • Remove the blanket not SQL_ALCHEMY_CONN.startswith("sqlite") guard in prepare_engine_args and replace it with a targeted check that only skips pool settings for in-memory SQLite (sqlite://, sqlite:///:memory:), which uses SingletonThreadPool that doesn't support max_overflow.
  • File-based SQLite now receives the same pool configuration as PostgreSQL and MySQL.
  • Update the SQLAlchemy docs link from 1.4 to 2.0.
  • Add unit tests covering both cases:
    • File-based SQLite gets pool settings through configure_orm.
    • In-memory SQLite skips pool settings (tested via prepare_engine_args directly, since configure_orm rejects sqlite:///:memory: as a relative path before reaching pool logic).

@jason810496 jason810496 self-assigned this Apr 8, 2026
@jason810496 jason810496 force-pushed the fix/sqite-sqlalchemy-pool-conf branch from 0d2ec20 to 539f56b Compare April 8, 2026 12:26
@jason810496 jason810496 marked this pull request as ready for review April 8, 2026 12:26
@jason810496 jason810496 requested a review from Copilot April 8, 2026 12:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Airflow’s SQLAlchemy engine configuration so that connection pool settings are applied to file-based SQLite connections (matching SQLAlchemy 2.0+ defaults), while still skipping pool settings for in-memory SQLite connections where they are not supported.

Changes:

  • Adjust prepare_engine_args to skip pool settings only for in-memory SQLite instead of all SQLite.
  • Update the SQLAlchemy docs link to the 2.0 documentation.
  • Add unit tests to validate pool settings for file-based SQLite and skipping behavior for in-memory SQLite.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
airflow-core/src/airflow/settings.py Refines pool-setting guard for SQLite and updates SQLAlchemy docs link.
airflow-core/tests/unit/core/test_sqlalchemy_config.py Adds tests for file-based SQLite pooling and in-memory SQLite pool-setting skip behavior.

Comment thread airflow-core/src/airflow/settings.py Outdated
Comment thread airflow-core/tests/unit/core/test_sqlalchemy_config.py
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread airflow-core/src/airflow/settings.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@jason810496 jason810496 force-pushed the fix/sqite-sqlalchemy-pool-conf branch from a40d548 to 7f22ef8 Compare April 16, 2026 13:00
@jason810496 jason810496 requested a review from Lee-W April 16, 2026 13:00
@jason810496 jason810496 force-pushed the fix/sqite-sqlalchemy-pool-conf branch from 7f22ef8 to 2c27de6 Compare April 17, 2026 06:13
Comment thread airflow-core/tests/unit/core/test_sqlalchemy_config.py Outdated
Copy link
Copy Markdown
Member Author

@jason810496 jason810496 left a comment

Choose a reason for hiding this comment

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

The only failing static check in CI was fixed in latest main, so I will merge it.

@jason810496 jason810496 added type:bug-fix Changelog: Bug Fixes backport-to-v3-2-test Mark PR with this label to backport to v3-2-test branch labels Apr 17, 2026
@jason810496 jason810496 merged commit d6ba3c4 into apache:main Apr 17, 2026
75 of 76 checks passed
@github-actions github-actions Bot added this to the Airflow 3.2.2 milestone Apr 17, 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.2 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.

github-actions Bot pushed a commit that referenced this pull request Apr 17, 2026
… SQLite (#64888)

* Enable SQLAlchemy connection pool settings for file-based SQLite

* Fix review comments

* Fix import make_url comment

* Address Wei's final nit
(cherry picked from commit d6ba3c4)

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.com>
@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

github-actions Bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Apr 17, 2026
… SQLite (apache#64888)

* Enable SQLAlchemy connection pool settings for file-based SQLite

* Fix review comments

* Fix import make_url comment

* Address Wei's final nit
(cherry picked from commit d6ba3c4)

Co-authored-by: Jason(Zhe-You) Liu <68415893+jason810496@users.noreply.github.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.

3 participants