Skip to content

Commit 939ce97

Browse files
Remove NullPool default, use QueuePool for network database
NullPool creates a new TCP connection per operation which is expensive for a network database like dqlite. Remove the get_pool_class override to let SQLAlchemy use its default QueuePool, matching the pattern used by PostgreSQL and MySQL dialects. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 57b6799 commit 939ce97

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

src/sqlalchemydqlite/base.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from typing import Any
44

5-
from sqlalchemy import pool
65
from sqlalchemy.dialects.sqlite.base import SQLiteDialect
76
from sqlalchemy.engine import URL
87
from sqlalchemy.engine.interfaces import DBAPIConnection, IsolationLevel
@@ -23,11 +22,6 @@ class DqliteDialect(SQLiteDialect):
2322
# Enable SQLAlchemy statement caching
2423
supports_statement_cache = True
2524

26-
# Default to NullPool since dqlite handles connection pooling internally
27-
@classmethod
28-
def get_pool_class(cls, url: URL) -> type[pool.Pool]:
29-
return pool.NullPool
30-
3125
@classmethod
3226
def import_dbapi(cls) -> Any:
3327
import dqlitedbapi

tests/test_dialect.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,20 @@ def test_ping_closes_cursor_even_on_error(self) -> None:
378378
mock_cursor.close.assert_called_once()
379379

380380

381+
class TestPoolClass:
382+
def test_sync_dialect_does_not_use_nullpool(self) -> None:
383+
"""Sync dialect should not default to NullPool for a network database."""
384+
from sqlalchemy import pool
385+
from sqlalchemy.engine import URL
386+
387+
url = URL.create("dqlite", host="localhost", port=9001, database="test")
388+
pool_class = DqliteDialect.get_pool_class(url)
389+
assert pool_class is not pool.NullPool, (
390+
"NullPool creates a new TCP connection per operation; "
391+
"a network database should use QueuePool"
392+
)
393+
394+
381395
class TestURLParsing:
382396
def test_parse_basic_url(self) -> None:
383397
url = URL.create("dqlite", host="localhost", port=9001, database="test")

0 commit comments

Comments
 (0)