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

mariadb.connect() silently ignores time_zone parameter/attribute, causing silent data corruption (Incompatibility with mysql.connector)

    XMLWordPrintable

Details

    • New Feature
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 1.1.12
    • None
    • DBAPI 2.0
    • "Raspbian GNU/Linux 13 (trixie)"

    Description

      Description
      When migrating from mysql-connector-python to mariadb (Python Connector), there is a critical discrepancy in how connection-level time zones are handled.

      In mysql.connector, passing time_zone='+00:00' as a keyword argument during connection initialization successfully sets the session time zone. Alternatively, setting it as an attribute post-connection works or raises an error if unsupported.

      However, the mariadb Python connector silently ignores this parameter without throwing any TypeError or NotSupportedError. Because it fails silently, developers assume the session is running in UTC, while the underlying connection remains in local time (e.g., CEST). This leads to silent data corruption when inserting string-based timestamps into TIMESTAMP columns, as the driver/database implicitly applies an unintended local timezone offset.

      Steps to Reproduce

      #!/usr/bin/env python3
       
      import mysql.connector
      import mariadb
       
      config = {
          "host": "127.0.0.1",
          "user": "myuser"
      }
       
      def run(conn):
          cursor = conn.cursor()
          
          cursor.execute("SELECT @@session.time_zone;")
          print("Initial:", cursor.fetchone()[0]) 
          conn.time_zone = "+00:00"
          cursor.execute("SELECT @@session.time_zone;")
          print("after time_zone attribute change", cursor.fetchone()[0])
       
      print("mysql.connector")
      conn = mysql.connector.connect(**config)
      run(conn)
      print("mariadb")
      conn = mariadb.connect(**config)
      run(conn)
      
      

      Output:
      mysql.connector
      Initial: SYSTEM
      after time_zone attribute change +00:00
      mariadb
      Initial: SYSTEM
      after time_zone attribute change SYSTEM

      Attachments

        Activity

          People

            georg Georg Richter
            duwo Wolfgang Dunkler
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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