]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Use SingletonThreadPool for in-memory SQLite
authorYongJieYongJie <KhooYongJie@gmx.com>
Wed, 28 Apr 2021 17:30:09 +0000 (13:30 -0400)
committerFederico Caselli <cfederico87@gmail.com>
Wed, 28 Apr 2021 18:52:34 +0000 (20:52 +0200)
database created using filename uri

Default to using ``SingletonThreadPool`` for in-memory SQLite databases
created using URI filenames. Previously the default pool used was the
``NullPool`` that precented sharing the same database between multiple
engines.

Fixes: #6379
Closes: #6380
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/6380
Pull-request-sha: 3b8024417a3a54c8269d43e40801aa4e58593540

Change-Id: Ice09622796455e796ede7711c98f3ceec13aa949

doc/build/changelog/unreleased_14/6379.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/sqlite/pysqlite.py
test/dialect/test_sqlite.py

diff --git a/doc/build/changelog/unreleased_14/6379.rst b/doc/build/changelog/unreleased_14/6379.rst
new file mode 100644 (file)
index 0000000..9ea82bc
--- /dev/null
@@ -0,0 +1,8 @@
+.. change::
+    :tags: usecase, sqlite
+    :tickets: 6379
+
+    Default to using ``SingletonThreadPool`` for in-memory SQLite databases
+    created using URI filenames. Previously the default pool used was the
+    ``NullPool`` that precented sharing the same database between multiple
+    engines.
index 0b091e73b648fd1d4f6caab7a546cd6e699d1bff..20a4bb7acb2831b030676bc2e1a5a0297e5bde0a 100644 (file)
@@ -474,7 +474,9 @@ class SQLiteDialect_pysqlite(SQLiteDialect):
 
     @classmethod
     def _is_url_file_db(cls, url):
-        if url.database and url.database != ":memory:":
+        if (url.database and url.database != ":memory:") and (
+            url.query.get("mode", None) != "memory"
+        ):
             return True
         else:
             return False
index 7fd7ac333cfa6be329ec1fbdd3ebd9476f317b83..bae97bb9a2ff6394dfbe83dccc831b16bf926e41 100644 (file)
@@ -710,6 +710,11 @@ class DialectTest(
         e = create_engine("sqlite+pysqlite:///:memory:")
         assert e.pool.__class__ is pool.SingletonThreadPool
 
+        e = create_engine(
+            "sqlite+pysqlite:///file:foo.db?mode=memory&uri=true"
+        )
+        assert e.pool.__class__ is pool.SingletonThreadPool
+
         e = create_engine("sqlite+pysqlite:///foo.db")
         assert e.pool.__class__ is pool.NullPool