Skip to content

Commit 1150733

Browse files
cleanup(sqlalchemy): pin dialect attributes and description
- ISSUE-89: pin dialect_description as "dqlite+dqlitedbapi" so SQLAlchemy ORM error-message formatting cannot silently change the rendered dialect identity across upgrades. - ISSUE-90: declare `supports_sane_isolation_level = True` explicitly. dqlite always enforces SERIALIZABLE; the reported level is trustworthy across transactions, so SQLAlchemy skips defensive isolation-level resets. - ISSUE-94: declare `supports_native_decimal = False` explicitly. Matches the inherited pysqlite default but pins the contract against upstream drift and matches the already-explicit `supports_native_boolean = True` pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 48e776b commit 1150733

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/sqlalchemydqlite/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ class DqliteDialect(SQLiteDialect):
8383
# applications introspect via ``engine.dialect.supported_isolation_levels``.
8484
supported_isolation_levels: tuple[str, ...] = ("SERIALIZABLE",)
8585

86+
# Since isolation is always SERIALIZABLE and cannot be weakened, the
87+
# reported isolation level is trustworthy across transactions. SQLAlchemy
88+
# skips defensive isolation-level resets when this is True.
89+
supports_sane_isolation_level = True
90+
91+
# dqlite/SQLite have no native DECIMAL type — values are stored as TEXT
92+
# or REAL. Declare explicitly to document the contract (matches pysqlite
93+
# inherited default, pinned here against upstream drift).
94+
supports_native_decimal = False
95+
8696
# Override the SQLite dialect's string-based DATE/DATETIME processors:
8797
# dqlitedbapi returns datetime objects (PEP 249), not ISO strings.
8898
colspecs = {

tests/test_dialect.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ def test_create_connect_args_custom(self) -> None:
4444
assert kwargs["address"] == "node1:9002"
4545
assert kwargs["database"] == "mydb"
4646

47+
def test_supports_sane_isolation_level(self) -> None:
48+
# dqlite always enforces SERIALIZABLE; the reported level is
49+
# trustworthy across transactions (ISSUE-90).
50+
assert DqliteDialect.supports_sane_isolation_level is True
51+
52+
def test_supports_native_decimal_false(self) -> None:
53+
# SQLite/dqlite has no native DECIMAL type (ISSUE-94).
54+
assert DqliteDialect.supports_native_decimal is False
55+
56+
def test_dialect_description(self) -> None:
57+
# Pin the derived dialect_description so SQLAlchemy upgrades cannot
58+
# silently change the rendered identity in ORM error messages
59+
# (ISSUE-89).
60+
assert DqliteDialect().dialect_description == "dqlite+dqlitedbapi"
61+
4762

4863
class TestDqliteDialectAio:
4964
def test_dialect_name(self) -> None:

0 commit comments

Comments
 (0)