Skip to content

Commit bdd9520

Browse files
committed
BUG23636962: Fix improper error message when creating a Session
This patch changes the output of the error message when connecting to a MySQL server that does not have X protocol plugin enabled. Tests were added for regression.
1 parent ef497bc commit bdd9520

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/mysqlx/protocol.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# MySQL Connector/Python - MySQL driver written in Python.
2-
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
33

44
# MySQL Connector/Python is licensed under the terms of the GPLv2
55
# <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
@@ -58,6 +58,9 @@ def read_message(self):
5858
def _read_message(self):
5959
hdr = self._stream.read(5)
6060
msg_len, msg_type = struct.unpack("<LB", hdr)
61+
if msg_type == 10:
62+
raise ProgrammingError("The connected server does not have the "
63+
"MySQL X protocol plugin enabled")
6164
payload = self._stream.read(msg_len - 1)
6265
msg_type_name = SERVER_MESSAGES.get(msg_type)
6366
if not msg_type_name:

tests/test_mysqlx_connection.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,16 @@ def test_ssl_connection(self):
440440
ssl_cert=ssl_cert, ssl_key=ssl_key)
441441
session = mysqlx.get_session(uri)
442442

443+
def test_disabled_x_protocol(self):
444+
node_session = mysqlx.get_node_session(self.connect_kwargs)
445+
res = node_session.sql("SHOW VARIABLES WHERE Variable_name = 'port'") \
446+
.execute().fetch_all()
447+
settings = self.connect_kwargs.copy()
448+
settings["port"] = res[0][1] # Lets use the MySQL classic port
449+
node_session.close()
450+
self.assertRaises(mysqlx.errors.ProgrammingError, mysqlx.get_session,
451+
settings)
452+
443453

444454
@unittest.skipIf(tests.MYSQL_VERSION < (5, 7, 12), "XPlugin not compatible")
445455
class MySQLxNodeSessionTests(tests.MySQLxTests):
@@ -619,3 +629,11 @@ def test_ssl_connection(self):
619629
host=config["host"], ssl_ca=ssl_ca,
620630
ssl_cert=ssl_cert, ssl_key=ssl_key)
621631
session = mysqlx.get_node_session(uri)
632+
633+
def test_disabled_x_protocol(self):
634+
res = self.session.sql("SHOW VARIABLES WHERE Variable_name = 'port'") \
635+
.execute().fetch_all()
636+
settings = self.connect_kwargs.copy()
637+
settings["port"] = res[0][1] # Lets use the MySQL classic port
638+
self.assertRaises(mysqlx.errors.ProgrammingError,
639+
mysqlx.get_node_session, settings)

0 commit comments

Comments
 (0)