]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
support utf8mb3 char encoding fully for mysqlclient, others
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 2 Oct 2021 15:53:55 +0000 (11:53 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 2 Oct 2021 20:54:33 +0000 (16:54 -0400)
Fixes to accommodate for the MariaDB 10.6 series, including backwards
incompatible changes in both the mariadb-connector Python driver (supported
on SQLAlchemy 1.4 only) as well as the native 10.6 client libraries that
are used automatically by the mysqlclient DBAPI (applies to both 1.3 and
1.4). The "utf8mb3" encoding symbol is now reported by these client
libraries when the encoding is stated as "utf8", leading to lookup and
encoding errors within the MySQL dialect that does not expect this symbol.
Updates to both the MySQL base library to accommodate for this utf8mb3
symbol being reported as well as to the test suite. Thanks to Georg Richter
for support.

Fixes: #7136
Fixes: #7115
Change-Id: I655d9d9868aef76037023d0c602b8a7c881780b0

doc/build/changelog/unreleased_13/7115.rst [new file with mode: 0644]
doc/build/changelog/unreleased_14/7115.rst [deleted file]
test/dialect/mysql/test_dialect.py

diff --git a/doc/build/changelog/unreleased_13/7115.rst b/doc/build/changelog/unreleased_13/7115.rst
new file mode 100644 (file)
index 0000000..1f2c7fc
--- /dev/null
@@ -0,0 +1,16 @@
+.. change::
+    :tags: bug, mysql, mariadb
+    :tickets: 7115, 7136
+    :versions: 1.4.26
+
+    Fixes to accommodate for the MariaDB 10.6 series, including backwards
+    incompatible changes in both the mariadb-connector Python driver (supported
+    on SQLAlchemy 1.4 only) as well as the native 10.6 client libraries that
+    are used automatically by the mysqlclient DBAPI (applies to both 1.3 and
+    1.4). The "utf8mb3" encoding symbol is now reported by these client
+    libraries when the encoding is stated as "utf8", leading to lookup and
+    encoding errors within the MySQL dialect that does not expect this symbol.
+    Updates to both the MySQL base library to accommodate for this utf8mb3
+    symbol being reported as well as to the test suite. Thanks to Georg Richter
+    for support.
+
diff --git a/doc/build/changelog/unreleased_14/7115.rst b/doc/build/changelog/unreleased_14/7115.rst
deleted file mode 100644 (file)
index 561e152..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-.. change::
-    :tags: bug, mysql, tests
-    :tickets: 7115
-
-    Updated test suite to pass correctly for MariaDB 10.6 when using the
-    mariadb-connector driver, which made some adjustments to default encoding.
-    Pull request courtesy Georg Richter.
-
index 57dd9d393ddbf599847b73aea158fdd56f42fe35..48fe3d3b1f68d17d76455ea798ade1814f64dd7d 100644 (file)
@@ -18,6 +18,7 @@ from sqlalchemy.testing import engines
 from sqlalchemy.testing import eq_
 from sqlalchemy.testing import expect_warnings
 from sqlalchemy.testing import fixtures
+from sqlalchemy.testing import in_
 from sqlalchemy.testing import is_
 from sqlalchemy.testing import mock
 from ...engine import test_deprecations
@@ -95,6 +96,8 @@ class BackendDialectTest(fixtures.TestBase):
 
 
 class DialectTest(fixtures.TestBase):
+    __backend__ = True
+
     @testing.combinations(
         (None, "cONnection was kILLEd", "InternalError", "pymysql", True),
         (None, "cONnection aLREady closed", "InternalError", "pymysql", True),
@@ -250,14 +253,31 @@ class DialectTest(fixtures.TestBase):
             "mariadb+pymysql",
         ]
     )
-    def test_special_encodings(self):
+    @testing.combinations(
+        ("utf8mb4",),
+        ("utf8",),
+    )
+    def test_special_encodings(self, enc):
 
-        for enc in ["utf8mb4", "utf8"]:
-            eng = engines.testing_engine(
-                options={"connect_args": {"charset": enc, "use_unicode": 0}}
-            )
-            conn = eng.connect()
-            eq_(conn.dialect._connection_charset, enc)
+        eng = engines.testing_engine(
+            options={"connect_args": {"charset": enc, "use_unicode": 0}}
+        )
+        conn = eng.connect()
+
+        detected = conn.dialect._connection_charset
+        if enc == "utf8mb4":
+            eq_(detected, enc)
+        else:
+            in_(detected, ["utf8", "utf8mb3"])
+
+    @testing.only_on("mariadb+mariadbconnector")
+    def test_mariadb_connector_special_encodings(self):
+
+        eng = engines.testing_engine()
+        conn = eng.connect()
+
+        detected = conn.dialect._connection_charset
+        eq_(detected, "utf8mb4")
 
 
 class ParseVersionTest(fixtures.TestBase):