New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
connections.py read_default_group = "client" #811
Comments
Alternatively, the read_default_group could be additional to [client] |
What is the behavior of the |
This is what I find. I will see what I can do to get documentation. So, the idea is to start off with the generic (client), and then overwrite/add changes as set in the specific (mysql) - but it may be a very good idea to add your own group too - eg [pymysql] - this would mean that the same config file could have specific switches for the PyMySQL connections. This could also allow for a config file to make settings for pymysql implementation without having to amend the application sourcecode. (It's a good, old, principle not to mix data with code - but sql settings are an area where this rule of thumb often falls short). The issue is especially relevant when using the same config file for, eg, mysqldump - which kicks up a fuss if there is a database setting in the client group. The following would work fine, (bearing in mind that the programmer can always set the group to read as [mysql] - with the client being the fall-back for values not set in the primary group.
|
https://dev.mysql.com/doc/refman/8.0/en/option-files.html#option-file-syntax
|
So this is what I found. https://dev.mysql.com/doc/refman/8.0/en/mysql-options.html
My interpretation is that if I set a group [pymysql] via
then the client group will also be read - and that this will be done when MYSQL_READ_DEFAULT_GROUP is called. |
In connections.py, on line 220, the Parser() initialisation should include the default groups path which is converted into an OrderedDict called _defaults in the parser (cf. line 1154 of configparser.py) ; the init specifies a default_section argument of (on line 600 of configparser.py); this default_section is different from the default_group! See the Pull Request #844 for a working solution The default group (as supplied via read_default_group = "pymysql") is set (or overridden by the coder), and will be used as the topmost group, with the fallback as specified in the parser initialisation default_section (client). configparser doesn't appear to allow for a chain of default sections, so it's not possible to accurately map the mysql client specifications allowing for client -> client-5.7 -> mysql -> mysql-5.6 -> pymysql etc, but supporting the 'client' group is definitely moving in the right direction. |
Pull request #844 This now works with both PY2 and PY3, and is backwards compatible; it also includes tests to support default groups correctly. |
I have also posted an issue on python ( https://bugs.python.org/issue39860 ) concerning cascading defaults. The pull request doesn't depend upon the issue being fixed in configparser, but it does support the fix. |
The [client] group does not normally include the database name, and including it will prevent mysqldump (and other services) from running.
Typically the database is set under the [mysql] group.
Without causing much trouble to existing code, the read_default_group switch could accept a tuple of groups (eg ('client','mysql'). However, the underlying configparser only allows a single default group. (Py2 ConfigParser doesn't allow one to set a default group, but one can set default values).
So, the default group should be 'client' and, following https://dev.mysql.com/doc/refman/8.0/en/option-files.html#option-file-syntax (and the way in which mysql cli works), and unless otherwise specified, the group should be '[pymysql]' (The application name), with the default group being [client].
The text was updated successfully, but these errors were encountered: