Details
-
New Feature
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
1.1.12
-
None
-
"Raspbian GNU/Linux 13 (trixie)"
-
3.13.5
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