From: Christophe Bornet Date: Fri, 31 Jan 2025 12:42:59 +0000 (-0500) Subject: Use AsyncAdaptedQueuePool in aiosqlite X-Git-Tag: rel_2_0_38~5^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=78445beeb5484f264adecfca5feb0c712929254a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Use AsyncAdaptedQueuePool in aiosqlite ### Description Change default pool in `aiosqlite` from `NullPool` to `AsyncAdaptedQueuePool`. This ensures consistency with pysqlite and least surprise when migrating from sync to async. See discussion in https://github.com/sqlalchemy/sqlalchemy/discussions/12285 Non regression tested by existing tests. ### Checklist This pull request is: - [ ] A documentation / typographical / small typing error fix - Good to go, no issue or tests are needed - [x] A short code fix - please include the issue number, and create an issue if none exists, which must include a complete example of the issue. one line code fixes without an issue and demonstration will not be accepted. - Please include: `Fixes: #` in the commit message - please include tests. one line code fixes without tests will not be accepted. - [ ] A new feature implementation - please include the issue number, and create an issue if none exists, which must include a complete example of how the feature would look. - Please include: `Fixes: #` in the commit message - please include tests. **Have a nice day!** Closes: #12291 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/12291 Pull-request-sha: 5a0872b8d431a6937eaf05fb132578aed5723b6a Change-Id: I96b4d0b5154b34cd26d3ad89774229b0f5d8686f (cherry picked from commit 11bac714a2e83f6f903b1faf36d744854635da66) --- diff --git a/doc/build/changelog/unreleased_20/12285.rst b/doc/build/changelog/unreleased_20/12285.rst new file mode 100644 index 0000000000..2c1451b360 --- /dev/null +++ b/doc/build/changelog/unreleased_20/12285.rst @@ -0,0 +1,6 @@ +.. change:: + :tags: change, sqlite, aiosqlite, asyncio, pool + :tickets: 12285 + + Changed default connection pool of aiosqlite from NullPool to AsyncAdaptedQueuePool for consistency with pysqlite. + diff --git a/lib/sqlalchemy/dialects/sqlite/aiosqlite.py b/lib/sqlalchemy/dialects/sqlite/aiosqlite.py index c777bf445b..828022454d 100644 --- a/lib/sqlalchemy/dialects/sqlite/aiosqlite.py +++ b/lib/sqlalchemy/dialects/sqlite/aiosqlite.py @@ -78,6 +78,28 @@ The solution is similar to :ref:`pysqlite_serializable`. This is achieved by the with the SQLite driver, as this function necessarily will also alter the ".isolation_level" setting. +.. _aiosqlite_pooling: + +Pooling Behavior +---------------- + +The SQLAlchemy ``aiosqlite`` DBAPI establishes the connection pool differently +based on the kind of SQLite database that's requested: + +* When a ``:memory:`` SQLite database is specified, the dialect by default + will use :class:`.StaticPool`. This pool maintains a single + connection, so that all access to the engine + use the same ``:memory:`` database. +* When a file-based database is specified, the dialect will use + :class:`.AsyncAdaptedQueuePool` as the source of connections. + + .. versionchanged:: 2.0.38 + + SQLite file database engines now use :class:`.AsyncAdaptedQueuePool` by default. + Previously, :class:`.NullPool` were used. The :class:`.NullPool` class + may be used by specifying it via the + :paramref:`_sa.create_engine.poolclass` parameter. + """ # noqa import asyncio @@ -380,7 +402,7 @@ class SQLiteDialect_aiosqlite(SQLiteDialect_pysqlite): @classmethod def get_pool_class(cls, url): if cls._is_url_file_db(url): - return pool.NullPool + return pool.AsyncAdaptedQueuePool else: return pool.StaticPool