Skip to content

Commit 88fcc3d

Browse files
Pin RETURNING and multivalues-insert flags locally on DqliteDialect
The SQLAlchemy 2.x tripartite RETURNING flags (insert_returning / update_returning / delete_returning) and supports_multivalues_insert were inherited silently from SQLiteDialect. Dqlite runs SQLite >= 3.35, so both RETURNING and multi-row INSERT VALUES are genuinely supported, but leaving the flags inherited means an upstream change to SQLiteDialect (e.g. version-gated discovery) could silently alter dqlite behaviour. Pin the four flags locally, matching the existing precedent for supports_native_boolean, supports_sane_isolation_level, and supports_native_decimal. Pin tests assert both the value and that the declaration lives in DqliteDialect.__dict__ so inheritance drift is caught. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3833a18 commit 88fcc3d

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/sqlalchemydqlite/base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ class DqliteDialect(SQLiteDialect):
9696
# inherited default, pinned here against upstream drift).
9797
supports_native_decimal = False
9898

99+
# dqlite runs SQLite >= 3.35, which supports the RETURNING clause on
100+
# INSERT / UPDATE / DELETE. Pin locally so upstream changes to
101+
# SQLiteDialect's RETURNING detection (e.g. version-gated discovery)
102+
# can't silently change dqlite behaviour. All three of SQLAlchemy 2.x's
103+
# tripartite RETURNING flags default to True on the parent class today.
104+
insert_returning = True
105+
update_returning = True
106+
delete_returning = True
107+
108+
# SQLite >= 3.7.11 supports multi-row INSERT VALUES, which SQLAlchemy's
109+
# insertmanyvalues optimisation depends on. Pin the flag so bulk-insert
110+
# behaviour stays stable against upstream dialect drift.
111+
supports_multivalues_insert = True
112+
99113
# Override the SQLite dialect's string-based DATE/DATETIME processors:
100114
# dqlitedbapi returns datetime objects (PEP 249), not ISO strings.
101115
colspecs = {

tests/test_dialect.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,23 @@ def test_supports_native_decimal_false(self) -> None:
5353
# SQLite/dqlite has no native DECIMAL type.
5454
assert DqliteDialect.supports_native_decimal is False
5555

56+
def test_returning_flags_pinned_locally(self) -> None:
57+
# dqlite runs SQLite >= 3.35, so RETURNING is supported. Pin the
58+
# three SQLAlchemy 2.x flags locally so upstream dialect changes
59+
# cannot silently alter dqlite behaviour.
60+
assert DqliteDialect.insert_returning is True
61+
assert DqliteDialect.update_returning is True
62+
assert DqliteDialect.delete_returning is True
63+
# Locally declared (not just inherited) so the pin is load-bearing.
64+
assert "insert_returning" in DqliteDialect.__dict__
65+
assert "update_returning" in DqliteDialect.__dict__
66+
assert "delete_returning" in DqliteDialect.__dict__
67+
68+
def test_supports_multivalues_insert_pinned_locally(self) -> None:
69+
# SQLite >= 3.7.11 supports multi-row INSERT VALUES; dqlite does too.
70+
assert DqliteDialect.supports_multivalues_insert is True
71+
assert "supports_multivalues_insert" in DqliteDialect.__dict__
72+
5673
def test_dialect_description(self) -> None:
5774
# Pin the derived dialect_description so SQLAlchemy upgrades cannot
5875
# silently change the rendered identity in ORM error messages.

0 commit comments

Comments
 (0)