Skip to content

Commit d679d87

Browse files
committed
BUG#35318413: Fix charset mapping for MySQL 8.1.0
Connector/Python fails to connect to a MySQL 8.1.0 server when setting `charset="utf8mb4"` and `collation="utf8mb4_0900_ai_ci"`. This is due to the wrong testing of the MySQL version and the respective loading of the incorrect charset mapping module. Change-Id: I3994c1158bc926766c9396da6515eb6063be168f
1 parent cd17c83 commit d679d87

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ v8.1.0
1414
- WL#15630: Remove Python 3.7 support
1515
- WL#15591: Improve the network module
1616
- BUG#35338384: PIP installs incompatible Connector/Python packages
17+
- BUG#35318413: Fix charset mapping for MySQL 8.1.0
1718
- BUG#35212199: Check for identifier quotes in the database name
1819

1920
v8.0.33

lib/mysql/connector/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ def set_mysql_version(cls, version: Tuple[int, ...]) -> None:
732732
version (tuple): MySQL version tuple.
733733
"""
734734
cls.mysql_version = version[:2]
735-
if cls.mysql_version == (8, 0):
735+
if cls.mysql_version >= (8, 0):
736736
cls.desc = MYSQL_CHARACTER_SETS
737737

738738
@classmethod
@@ -815,7 +815,7 @@ def get_charset_info(
815815
except IndexError as err:
816816
raise ProgrammingError(f"Character set ID {charset} unknown") from err
817817

818-
if charset in ("utf8", "utf-8") and cls.mysql_version == (8, 0):
818+
if charset in ("utf8", "utf-8") and cls.mysql_version >= (8, 0):
819819
charset = "utf8mb4"
820820
if charset is not None and collation is None:
821821
info = cls.get_default_collation(charset)

tests/cext/test_cext_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
# Copyright (c) 2014, 2022, Oracle and/or its affiliates.
3+
# Copyright (c) 2014, 2023, Oracle and/or its affiliates.
44
#
55
# This program is free software; you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License, version 2.0, as
@@ -339,7 +339,7 @@ def test_get_server_version(self):
339339

340340
self.assertTrue(3 < version[0] < 9)
341341
self.assertTrue(0 <= version[1] < 20)
342-
self.assertTrue(0 < version[2] < 99)
342+
self.assertTrue(0 <= version[2] < 99)
343343

344344
def test_thread_id(self):
345345
cmy = MySQL()

tests/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,7 @@ def test_set_charset_collation(self):
15701570
self.cnx.set_charset_collation(collation=collation)
15711571
self.assertEqual(DEFAULT_CONFIGURATION["charset"], self.cnx.charset)
15721572

1573-
utf8_charset = "utf8mb3" if tests.MYSQL_VERSION[:2] == (8, 0) else "utf8"
1573+
utf8_charset = "utf8mb3" if tests.MYSQL_VERSION[:2] >= (8, 0) else "utf8"
15741574
self.cnx.set_charset_collation(utf8_charset)
15751575
self.assertEqual(33, self.cnx._charset_id)
15761576

tests/test_constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ class CharacterSetTests(tests.MySQLConnectorTests):
341341

342342
"""Tests for constants.CharacterSet"""
343343

344-
utf8_charset = "utf8mb3" if tests.MYSQL_VERSION[:2] == (8, 0) else "utf8"
344+
utf8_charset = "utf8mb3" if tests.MYSQL_VERSION[:2] >= (8, 0) else "utf8"
345345

346346
def test_get_info(self):
347347
"""Get info about charset using MySQL ID"""

0 commit comments

Comments
 (0)