Skip to content

Commit 47ec0c1

Browse files
Import leader-change error codes from dqlitewire
Drop the per-dialect copy of the 10250/10506 frozenset used by is_disconnect and import from dqlitewire.constants instead. The wire package is the authoritative home for protocol-level constants that more than one downstream package consumes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6135887 commit 47ec0c1

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

src/sqlalchemydqlite/base.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import dqliteclient.exceptions as _client_exc
1717
import dqlitedbapi.exceptions as _dbapi_exc
18+
from dqlitewire import LEADER_ERROR_CODES as _LEADER_CHANGE_CODES
1819

1920

2021
class _DqliteDateTime(sqltypes.DateTime):
@@ -249,13 +250,6 @@ def set_isolation_level(self, dbapi_connection: DBAPIConnection, level: str | No
249250
"Not connected",
250251
)
251252

252-
# Server-side SQLite error codes that mean the connection is useless
253-
# even if the TCP socket is still alive — kept in sync with the
254-
# client's _LEADER_ERROR_CODES.
255-
# SQLITE_IOERR_NOT_LEADER = SQLITE_IOERR | (40 << 8) = 10250
256-
# SQLITE_IOERR_LEADERSHIP_LOST = SQLITE_IOERR | (41 << 8) = 10506
257-
_LEADER_CHANGE_CODES: frozenset[int] = frozenset({10250, 10506})
258-
259253
def is_disconnect(self, e: Any, connection: Any, cursor: Any) -> bool:
260254
"""Detect whether an exception indicates a broken connection.
261255
@@ -274,7 +268,7 @@ def is_disconnect(self, e: Any, connection: Any, cursor: Any) -> bool:
274268
# Leader-change error codes signal that the connection is useless
275269
# even though it's TCP-alive.
276270
for err in (_dbapi_exc.OperationalError, _client_exc.OperationalError):
277-
if isinstance(e, err) and getattr(e, "code", None) in self._LEADER_CHANGE_CODES:
271+
if isinstance(e, err) and getattr(e, "code", None) in _LEADER_CHANGE_CODES:
278272
return True
279273
# Legacy substring fallback — kept so we still catch anything
280274
# that wasn't modelled as a specific exception type yet.

0 commit comments

Comments
 (0)