Skip to content

Commit 59ee210

Browse files
committed
BUG25349794: Add read_default_file alias for option_files in connect()
This patch adds an alias read_default_file for option_files, which allows more compatibility with other MySQL Python drivers. A test was added for regression.
1 parent fd8f08e commit 59ee210

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/mysql/connector/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License, version 2.0, as
@@ -143,6 +143,10 @@ def connect(*args, **kwargs):
143143
Returns MySQLConnection or PooledMySQLConnection.
144144
"""
145145
# Option files
146+
if 'read_default_file' in kwargs:
147+
kwargs['option_files'] = kwargs['read_default_file']
148+
kwargs.pop('read_default_file')
149+
146150
if 'option_files' in kwargs:
147151
new_config = read_option_files(**kwargs)
148152
return connect(**new_config)

lib/mysql/connector/abstracts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ def config(self, **kwargs):
281281
('username', 'user'),
282282
('passwd', 'password'),
283283
('connect_timeout', 'connection_timeout'),
284+
('read_default_file', 'option_files') ,
284285
]
285286
for compat, translate in compat_map:
286287
try:

tests/test_bugs.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5677,3 +5677,27 @@ def test_connection_collation_utf8mb4_0900_bin(self):
56775677

56785678
cnx = self.cnx.__class__(**config)
56795679
cnx.close()
5680+
5681+
5682+
class BugOra25349794(tests.MySQLConnectorTests):
5683+
"""BUG#25349794: ADD READ_DEFAULT_FILE ARGUMENT FOR CONNECT().
5684+
"""
5685+
def setUp(self):
5686+
pass
5687+
5688+
def tearDown(self):
5689+
pass
5690+
5691+
@foreach_cnx()
5692+
def test_read_default_file_alias(self):
5693+
opt_file = os.path.join("tests", "data", "option_files", "pool.cnf")
5694+
config = tests.get_mysql_config()
5695+
5696+
if tests.MYSQL_VERSION < (5, 7):
5697+
config["client_flags"] = [-constants.ClientFlag.CONNECT_ARGS]
5698+
5699+
conn = mysql.connector.connect(read_default_file=opt_file,
5700+
option_groups=["pooling"], **config)
5701+
self.assertEqual("my_pool", conn.pool_name)
5702+
mysql.connector._CONNECTION_POOLS = {}
5703+
conn.close()

0 commit comments

Comments
 (0)