Skip to content

Commit 0b95198

Browse files
committed
BUG19170287: Fix duplicate section error with Python v3
When an option file containing duplicate section was read by connector python, a DuplcateSectionError was being raised with Python v3. This patch fixes the issue by using parameter strict=False while instantiating ConfigParser with Python v3. A unit test has been added for BUG#19170287.
1 parent 7c4fc3d commit 0b95198

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

lib/mysql/connector/optionfiles.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ def __init__(self, files=None, keep_dashes=True): # pylint: disable=W0231
6767

6868
self._options_dict = {}
6969

70-
SafeConfigParser.__init__(self)
70+
if PY2:
71+
SafeConfigParser.__init__(self)
72+
else:
73+
SafeConfigParser.__init__(self, strict=False)
74+
7175
self.default_extension = DEFAULT_EXTENSIONS[os.name]
7276
self.keep_dashes = keep_dashes
7377

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[connector_python]
2+
user=root
3+
password=mypass
4+
database=cpydata
5+
port=10000
6+
7+
[connector_python]
8+
user=mysql
9+
password=mypass
10+
database=duplicate_data

tests/test_bugs.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,3 +2722,22 @@ def test_row_to_python(self):
27222722
self.cur.execute("INSERT INTO {0} (c1) VALUES (NULL)".format(self.tbl))
27232723
self.cur.execute("SELECT * FROM {0}".format(self.tbl))
27242724
self.assertEqual((None, 2), self.cur.fetchone())
2725+
2726+
2727+
class BugOra19170287(tests.MySQLConnectorTests):
2728+
"""BUG#19170287: DUPLICATE OPTION_GROUPS RAISING ERROR WITH PYTHON 3
2729+
"""
2730+
def test_duplicate_groups(self):
2731+
option_file_dir = os.path.join('tests', 'data', 'option_files')
2732+
opt_file = os.path.join(option_file_dir, 'dup_groups.cnf')
2733+
config = tests.get_mysql_config()
2734+
2735+
cnx = mysql.connector.connect(**config)
2736+
exp = {
2737+
u'password': u'mypass',
2738+
u'user': u'mysql',
2739+
u'database': u'duplicate_data',
2740+
u'port': 10000
2741+
}
2742+
self.assertEqual(exp, cnx._read_option_files(
2743+
{'option_files': opt_file}))

0 commit comments

Comments
 (0)