Skip to content

Commit ac3a5bf

Browse files
committed
BUG#37410052: Wrong exception message being shown when
ConnectionRefusedError is raised by the client This patch fixes the incorrect error message which is being shown by the client when ConnectionRefusedError is being raised while connecting with a MySQL server. Change-Id: I6d99a0ee68e66105c17c975fa9e30717574fea5a
1 parent a611aee commit ac3a5bf

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ v9.3.0
1818
- BUG#37453587: Github links in PyPI project's pages do not work
1919
- BUG#37447394: Unable to escape a parameter marker (`%s`) used in a query that should not be treated as a parameter marker
2020
- BUG#37418436: Arbitrary File Read in MySQL Python Client library
21+
- BUG#37410052: Bad formatting of exceptions when connecting with Unix sockets
2122
- BUG#37399636: The C-extension has a memory leak when working with prepared statements
2223
- BUG#37275524: Exception is not interpreted properly on prepared statements when C extension is in use
2324
- BUG#36098290: mysql-connector-python is distributed without setup.py or pyproject.toml

mysql-connector-python/lib/mysql/connector/network.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ def open_connection(self) -> None:
788788

789789
(self._family, socktype, proto, _, sockaddr) = addrinfo
790790

791-
# Instanciate the socket and connect
791+
# Instantiate the socket and connect
792792
try:
793793
self.sock = socket.socket(self._family, socktype, proto)
794794
self.sock.settimeout(self._connection_timeout)
@@ -804,12 +804,8 @@ def open_connection(self) -> None:
804804
) from err
805805
except IOError as err:
806806
raise InterfaceError(
807-
errno=2002,
808-
values=(
809-
self.server_host,
810-
self.server_port,
811-
_strioerror(err),
812-
),
807+
errno=2003,
808+
values=(self.server_host, self.server_port, _strioerror(err)),
813809
) from err
814810
except Exception as err:
815-
raise OperationalError(str(err)) from err
811+
raise InterfaceError(str(err)) from err

mysql-connector-python/tests/test_bugs.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8973,3 +8973,32 @@ def test_bug37275524(self):
89738973
cur.execute(f"CREATE TABLE {self.table_name} (id INT PRIMARY KEY)")
89748974
cur.execute(f"INSERT INTO {self.table_name} (id) VALUES (1)")
89758975
cur.execute(f"INSERT INTO {self.table_name} (id) VALUES (1)")
8976+
8977+
class BugOra37410052(tests.MySQLConnectorTests):
8978+
"""BUG#37410052: Wrong exception message being shown when ConnectionRefusedError is raised
8979+
by the client
8980+
8981+
ConnectionRefusedError is not being correctly formatted when being raised by the
8982+
client while connecting with a MySQL server using pure-python implementation of
8983+
Connector/Python.
8984+
8985+
This patch fixes this issue by changing the error log message structure.
8986+
"""
8987+
8988+
def test_incorrect_host_err_msg(self):
8989+
config = tests.get_mysql_config()
8990+
config["port"] = 4875
8991+
config["use_pure"] = True
8992+
config["unix_socket"] = None
8993+
cnx = MySQLConnection
8994+
8995+
self.assertRaises(errors.InterfaceError, cnx, **config)
8996+
try:
8997+
with cnx(**config) as _:
8998+
pass
8999+
except errors.InterfaceError as err:
9000+
self.assertNotIn(
9001+
"%-.100s",
9002+
str(err),
9003+
"Error message cannot contain unstructured bind address",
9004+
)

0 commit comments

Comments
 (0)