Skip to content

fix(datasource): dispose SQLAlchemy engine when removing pool - #1362

Open
ashen-forest wants to merge 2 commits into
dataease:mainfrom
ashen-forest:fix/1358-sessionmaker-pool-dispose
Open

fix(datasource): dispose SQLAlchemy engine when removing pool#1362
ashen-forest wants to merge 2 commits into
dataease:mainfrom
ashen-forest:fix/1358-sessionmaker-pool-dispose

Conversation

@ashen-forest

@ashen-forest ashen-forest commented Sep 9, 2026

Copy link
Copy Markdown

What

Fixes #1358.

ConnectionPoolManager caches SQLAlchemy sessionmaker factories, but the eviction, remove_pool(), and close_all() paths call .close() on those factories. sessionmaker does not expose an instance close() method, so datasource updates can fail with:

AttributeError: 'sessionmaker' object has no attribute 'close'

This change keeps the public behavior of get_pool() unchanged while storing both the session factory and its bound Engine in the LRU cache. Pool cleanup now calls Engine.dispose(), which is responsible for disposing the underlying SQLAlchemy connection pool.

Changes

  • Keep (session_factory, engine) in ConnectionPoolManager cache entries.
  • Return the same cached sessionmaker factory to callers.
  • Dispose the bound engine on LRU eviction, remove_pool(), and close_all().
  • Add regression tests for all three cleanup paths.

Tests

Added regression coverage for:

  • explicit pool removal
  • LRU pool eviction
  • closing all managed pools

@ashen-forest ashen-forest changed the title Fix/1358 sessionmaker pool dispose fix(datasource): dispose SQLAlchemy engine when removing pool Sep 9, 2026
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.

[BUG]SQLServer数据源偶发保存失败

1 participant