Skip to content

Commit 19ebbcb

Browse files
Validate PrepareRequest.schema is 0 or 1 at construction
PrepareRequest was the only message with a user-settable schema field that accepted arbitrary values. Invalid schema values would be packed into the wire header and only rejected by the server, with no client-side error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e744be7 commit 19ebbcb

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/dqlitewire/messages/requests.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class PrepareRequest(Message):
144144

145145
def __post_init__(self) -> None:
146146
_check_uint64("db_id", self.db_id)
147+
if self.schema not in (0, 1):
148+
raise ValueError(f"schema must be 0 or 1, got {self.schema}")
147149

148150
def _get_schema(self) -> int:
149151
return self.schema

tests/test_messages_requests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ def test_default_schema_is_0_matching_go(self) -> None:
126126
header = Header.decode(encoded[:HEADER_SIZE])
127127
assert header.schema == 0
128128

129+
def test_rejects_invalid_schema(self) -> None:
130+
"""PrepareRequest should reject schema values other than 0 or 1."""
131+
import pytest
132+
133+
with pytest.raises(ValueError, match="schema must be 0 or 1"):
134+
PrepareRequest(db_id=1, sql="SELECT 1", schema=2)
135+
136+
with pytest.raises(ValueError, match="schema must be 0 or 1"):
137+
PrepareRequest(db_id=1, sql="SELECT 1", schema=-1)
138+
129139

130140
class TestExecRequest:
131141
def test_schema_v0_for_small_params(self) -> None:

0 commit comments

Comments
 (0)