Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
1.1.14
-
None
-
3.12
Description
mariadb-connector-python raises
SystemError: <method 'fetchrows' of 'mariadb.cursor' objects>
returned a result with an exception set
whenever a resultset contains a DATE, DATETIME or TIMESTAMP value with a
zero component – e.g. '2008-08-00' (day=0) or the zero-date
'0000-00-00 00:00:00'. Such values are accepted by MariaDB under a lenient
sql_mode and are common in legacy data. The error aborts the whole cursor:
no rows of the batch are returned.
Root cause: the C code calls PyDate_FromDate()/PyDateTime_FromDateAndTime()
directly. CPython sets a ValueError ("day is out of range for month") but
the C function returns a non-NULL result with the error still set, which
violates the C-API protocol and makes the interpreter raise SystemError.
Minimal repro (autocontained):
import mariadb
conn = mariadb.connect(host=..., user=..., password=..., database=...)
cur = conn.cursor()
cur.execute("SET SESSION sql_mode=''")
cur.execute("DROP TABLE IF EXISTS conpy_repro")
cur.execute("CREATE TABLE conpy_repro (id INT PRIMARY KEY, d DATE)")
cur.execute("INSERT INTO conpy_repro VALUES (1, '2008-08-00')")
cur.execute("SELECT id, d FROM conpy_repro WHERE id = 1")
print(cur.fetchall()) # SystemError here
Environment: connector-python 1.1.14, Python 3.12, Windows 11, legacy
MariaDB server with lenient sql_mode.
Expected: values Python cannot represent should be returned as None (as
mysqlclient and PyMySQL do for legacy data), never a SystemError that
breaks the cursor.
A PR implementing the fix + integration test will be linked shortly.