Skip to content

Commit de16cb5

Browse files
Cycle 21: tolerate non-numeric SQLite version suffixes
'3.46.0-alpha' or '3.46.0rc1' used to raise ValueError inside _get_server_version_info's int() call, which was silently caught by the OperationalError/DqliteConnectionError except and triggered the (3, 0, 0) fallback. That masked a real parse issue and pinned the dialect to ancient-version behavior whenever the server shipped a pre-release build. Now we strip trailing non-digits per component and parse the numeric prefix. 3.46.0-alpha -> (3, 46, 0). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e647df7 commit de16cb5

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/sqlalchemydqlite/base.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,27 @@ def do_ping(self, dbapi_connection: Any) -> bool:
224224
def _get_server_version_info(self, connection: Any) -> tuple[int, ...]:
225225
"""Return the server version as a tuple.
226226
227-
dqlite uses SQLite internally, so we return SQLite version.
227+
dqlite uses SQLite internally, so we return SQLite version. The
228+
parser is defensive: SQLite occasionally ships with suffixes
229+
(``3.46.0-alpha``, ``3.46.0rc1``) and a non-numeric part would
230+
otherwise raise ``ValueError`` on ``int()`` — we strip any
231+
trailing non-digit characters per component so the numeric
232+
prefix still parses.
228233
"""
234+
import re
235+
229236
try:
230237
result = connection.exec_driver_sql("SELECT sqlite_version()")
231238
version_str = result.scalar()
232239
if version_str:
233-
return tuple(int(x) for x in version_str.split("."))
240+
parts: list[int] = []
241+
for component in version_str.split("."):
242+
m = re.match(r"\d+", component)
243+
if not m:
244+
break
245+
parts.append(int(m.group(0)))
246+
if parts:
247+
return tuple(parts)
234248
except (
235249
_dbapi_exc.OperationalError,
236250
_client_exc.DqliteConnectionError,

uv.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)