]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Use SingletonThreadPool for in-memory SQLite database 6380/head
authorYongJieYongJie <KhooYongJie@gmx.com>
Wed, 28 Apr 2021 00:50:07 +0000 (08:50 +0800)
committerYongJieYongJie <KhooYongJie@gmx.com>
Wed, 28 Apr 2021 00:56:26 +0000 (08:56 +0800)
  Fix bug where NullPool is used for in-memory SQLite created using
  filename uri instead of ":memory:".

  Checks for in-memory SQLite database created using filename uri like
  "file:foo.db?mode=memory&uri=true" in addition to in-memory SQLite
  database created using the standard ":memory:".

Fixes: #6379
lib/sqlalchemy/dialects/sqlite/pysqlite.py
test/dialect/test_sqlite.py

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