Skip to content

Commit e4c5555

Browse files
Pin _classify_operational dispatch for code=0 and code=None
Upstream's gateway emits FailureResponse(code=0, "empty statement") on empty / comment-only / no-bound-parameters SQL. The wire layer accepts the code; the dbapi classifier should route it through to the default OperationalError (no special PEP 249 mapping). Pin both the code=0 (empty-statement upstream emission) and the code=None (wire-decode / ProtocolError-wrapped) dispatches. Test-only addition; no production code change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0393790 commit e4c5555

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Pin: ``_classify_operational(0)`` routes ``FailureResponse(code=0,
2+
"empty statement")`` to a clean ``OperationalError``.
3+
4+
Upstream's gateway emits ``failure(req, 0, "empty statement")`` on
5+
empty / comment-only SQL; the wire layer accepts the code (after the
6+
fix). The dbapi classifier dispatches by primary code via the
7+
``_CODE_TO_EXCEPTION`` table; code 0 falls through to the default
8+
``OperationalError`` class and is exposed to the user with the
9+
original message preserved.
10+
"""
11+
12+
from __future__ import annotations
13+
14+
from dqlitedbapi.cursor import _classify_operational
15+
from dqlitedbapi.exceptions import OperationalError
16+
17+
18+
def test_classify_operational_code_zero_returns_operational_error_class() -> None:
19+
"""Code 0 is not mapped in _CODE_TO_EXCEPTION; the classifier
20+
falls through to the default OperationalError class."""
21+
cls = _classify_operational(0)
22+
assert cls is OperationalError
23+
24+
25+
def test_classify_operational_code_none_returns_operational_error_class() -> None:
26+
"""Wire-decode / ProtocolError-wrapped errors carry code=None
27+
and fall through to OperationalError too."""
28+
cls = _classify_operational(None)
29+
assert cls is OperationalError

0 commit comments

Comments
 (0)