Uploaded image for project: 'MariaDB Connector/Python'
  1. MariaDB Connector/Python
  2. CONPY-368

fetchrows raises SystemError on DATE/DATETIME with a zero component (e.g. '2008-08-00', '0000-00-00')

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 1.1.14
    • 1.1.15, 2.0.0-rc3
    • Generic
    • 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.

      Attachments

        Activity

          People

            diego dupin Diego Dupin
            coveiro Rafael Fabian Ruske
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.