Bug #73673 Ignore missing option_files
Submitted: 21 Aug 2014 14:58 Modified: 9 Jan 2015 15:57
Reporter: Andrew Garner Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / Python Severity:S4 (Feature request)
Version:2.0.0 OS:Any
Assigned to: CPU Architecture:Any
Triage: Needs Triage: D5 (Feature request)

[21 Aug 2014 14:58] Andrew Garner
Description:
When specifying option_files to connect() in 2.0.0, the operation fails if any of the option_files entries do not exist.  Often it would be convenient to include ~/.my.cnf and simply ignore the config if it does not exist.

While this can be accomplished by filtering the list of option_files before passing to connect, that can be a little racy and I think an explicit option to do this would be more robust.

How to repeat:
>>> import mysql.connector
>>> mysql.connector.connect(option_files=['does_not_exist.cnf'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mysql/connector/__init__.py", line 154, in connect
    return MySQLConnection(*args, **kwargs)
  File "mysql/connector/connection.py", line 129, in __init__
    self.connect(**kwargs)
  File "mysql/connector/connection.py", line 504, in connect
    self.config(**kwargs)
  File "mysql/connector/connection.py", line 307, in config
    self._read_option_files(config)
  File "mysql/connector/connection.py", line 261, in _read_option_files
    keep_dashes=False)
  File "mysql/connector/optionfiles.py", line 81, in __init__
    self._parse_options(list(self.files))
  File "mysql/connector/optionfiles.py", line 132, in _parse_options
    file_, str(exc)))
ValueError: Failed reading file 'does_not_exist.cnf': [Errno 2] No such file or directory: 'does_not_exist.cnf'

Suggested fix:
Provide a convenient way to ignore missing option files.
[25 Aug 2014 11:03] Umesh Shastry
Hello Andrew,

Thank you for the bug report.
Verified as described.

Thanks,
Umesh
[25 Aug 2014 11:04] Umesh Shastry
//

>>> import mysql.connector
>>> mysql.connector.connect(option_files=['does_not_exist.cnf'])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/mysql/connector/__init__.py", line 154, in connect
    return MySQLConnection(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/mysql/connector/connection.py", line 129, in __init__
    self.connect(**kwargs)
  File "/usr/lib/python2.6/site-packages/mysql/connector/connection.py", line 504, in connect
    self.config(**kwargs)
  File "/usr/lib/python2.6/site-packages/mysql/connector/connection.py", line 307, in config
    self._read_option_files(config)
  File "/usr/lib/python2.6/site-packages/mysql/connector/connection.py", line 261, in _read_option_files
    keep_dashes=False)
  File "/usr/lib/python2.6/site-packages/mysql/connector/optionfiles.py", line 81, in __init__
    self._parse_options(list(self.files))
  File "/usr/lib/python2.6/site-packages/mysql/connector/optionfiles.py", line 132, in _parse_options
    file_, str(exc)))
ValueError: Failed reading file 'does_not_exist.cnf': [Errno 2] No such file or directory: 'does_not_exist.cnf'
>>>