Repository navigation
fix: build null and static pools from PoolSettings, and stop recommending the sync queue pool - #61
Merged
Merged
Conversation
…ding the sync queue pool
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #53.
Problem
_apply_pool_settingspassedpool_size,max_overflowandpool_timeoutto every pool class, soPoolSettings(kind="null")andPoolSettings(kind="static", ...)could not build an engine.PoolSettingsalways carries all three, so neither kind has ever worked from settings. The docstrings also recommended"queue", a sync pool that SQLAlchemy refuses on an asyncio engine.Change
pool_size,max_overflowandpool_timeoutgo to the engine only whenissubclass(poolclass, QueuePool): the async queue pools, registered subclasses, and the classinstrument_pool_classbuilds.pool_recycleandpool_pre_pinggo to every pool. The docstring now describes the code.PoolSettings(kind="static")is documented as what SQLAlchemy builds: one shared connection, for tests. The validator now rejectssize > 1forstatic, with a message that points atasync_adapted_queueplusmax_overflow=0, and no longer checksmax_overflow, which doesn't apply to it. The "high-throughput static pool" example is gone.AsyncSessionManager(poolclass=None)is the new default. It meanspool_settings.kindwhenpool_settingsis given, and"null"otherwise. Without this, the kwargs filter would have turnedAsyncSessionManager(url, pool_settings=...)from a crash into a silentNullPoolthat ignores the sizes.AsyncSessionManagerand builder docstrings:"queue"becomes"async_adapted_queue", and"null"is described as one connection per checkout, for tests.Considered and rejected
"queue"/"singleton_thread"fromPoolRegistry, or resolving"queue"toAsyncAdaptedQueuePool. The registry andresolve_pool_classare public and can serve a sync engine (a migrations engine built from the samePoolSettings). Repointing a public name would break that. On the async manager, SQLAlchemy already fails loudly at construction."async_adapted_queue"the manager's default withoutpool_settings. Test suites that build a manager per test and per event loop rely onNullPool, because a pooled asyncpg connection can't cross loops.Who notices
kind="static"andsize > 1now gets aValidationErrorat config load. That config never built an engine before (TypeError atcreate_async_engine), so no working setup changes.PoolSettings(kind="static", max_overflow=20)now validates (overflow doesn't apply). It also never built an engine before.async_adapted_queueconfigs or forAsyncSessionManager(url)withoutpool_settings.Evidence
New tests, run against the old
engine.py/manager.py/settings/postgres.py(swapped in fromorigin/master): 10 failed, 4 passed. The 4 passing are the queue-pool controls. The failing ones are theNullPool/StaticPoolkwargs, every pool kind building an engine fromPoolSettings,pool_settingswithoutpoolclass, the instrumented static pool, the new validator, and an integration test that runsSELECT 1throughcreate_async_session_managerfornullandstaticon PostgreSQL 17.The reporter's script after the fix (static with
size=1):Gate:
make checkclean;make test640 passed, coverage 93.77%.