Skip to content

Commit 1b0743d

Browse files
Pin returns_native_bytes on the dqlite dialect
dqlitedbapi returns native Python bytes for BLOB columns. Declaring returns_native_bytes = True lets LargeBinary.result_processor skip the redundant bytes() wrap on every cell and guards against a future DefaultDialect default flip that would silently re-introduce the copy. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 748bdfe commit 1b0743d

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/sqlalchemydqlite/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ class DqliteDialect(SQLiteDialect):
7474
# Enable SQLAlchemy statement caching
7575
supports_statement_cache = True
7676

77+
# dqlitedbapi returns native Python ``bytes`` for BLOB columns (the
78+
# wire codec emits ``bytes`` for ``ValueType.BLOB``, and the
79+
# PEP 249 ``Binary()`` constructor returns ``bytes``). Pin True
80+
# locally so ``LargeBinary.result_processor`` can skip the redundant
81+
# ``bytes(value)`` wrap on every BLOB cell.
82+
returns_native_bytes = True
83+
7784
# dqlite's wire protocol has a first-class BOOLEAN tag
7885
# (``ValueType.BOOLEAN = 11``); the server returns native Python
7986
# booleans for columns tagged BOOLEAN and dqlitedbapi passes them

tests/test_dialect.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ def test_insert_path_flags_pinned_locally(self, flag: str) -> None:
104104
assert getattr(DqliteDialect, flag) is True
105105
assert flag in DqliteDialect.__dict__
106106

107+
def test_returns_native_bytes_pinned_locally(self) -> None:
108+
"""dqlitedbapi returns native Python ``bytes`` for BLOB columns;
109+
pin True locally so ``LargeBinary.result_processor`` skips the
110+
redundant ``bytes(value)`` wrap on every BLOB cell, and so a
111+
future DefaultDialect default flip cannot silently add overhead.
112+
"""
113+
assert DqliteDialect.returns_native_bytes is True
114+
assert "returns_native_bytes" in DqliteDialect.__dict__
115+
107116
def test_dialect_description(self) -> None:
108117
# Pin the derived dialect_description so SQLAlchemy upgrades cannot
109118
# silently change the rendered identity in ORM error messages.

0 commit comments

Comments
 (0)