Skip to content
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

ConfigParser does not handle options without values #51254

Closed
mkindahl mannequin opened this issue Sep 27, 2009 · 16 comments
Closed

ConfigParser does not handle options without values #51254

mkindahl mannequin opened this issue Sep 27, 2009 · 16 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@mkindahl
Copy link
Mannequin

mkindahl mannequin commented Sep 27, 2009

BPO 7005
Nosy @freddrake, @merwok, @ambv
Files
  • cfgparser-1.patch: Patch Support "bpo-" in Misc/NEWS #1 for allowing ConfigParser to read configuration files containing options without values
  • cfgparser-2.patch: Patch Rename README to README.rst and enhance formatting #2 for allowing ConfigParser to read configuration files containing options without values
  • cpsample.py: Diagnostic script
  • issue-7005.patch: Patch (Python 2)
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/freddrake'
    closed_at = <Date 2010-09-03.04:24:03.038>
    created_at = <Date 2009-09-27.06:14:03.497>
    labels = ['type-feature', 'library']
    title = 'ConfigParser does not handle options without values'
    updated_at = <Date 2010-09-03.04:24:03.037>
    user = 'https://bugs.python.org/mkindahl'

    bugs.python.org fields:

    activity = <Date 2010-09-03.04:24:03.037>
    actor = 'fdrake'
    assignee = 'fdrake'
    closed = True
    closed_date = <Date 2010-09-03.04:24:03.038>
    closer = 'fdrake'
    components = ['Library (Lib)']
    creation = <Date 2009-09-27.06:14:03.497>
    creator = 'mkindahl'
    dependencies = []
    files = ['14985', '14993', '18717', '18718']
    hgrepos = []
    issue_num = 7005
    keywords = ['patch']
    message_count = 16.0
    messages = ['93168', '93183', '93199', '93200', '93259', '93345', '95244', '99454', '99558', '99559', '114965', '114968', '115407', '115414', '115416', '115417']
    nosy_count = 5.0
    nosy_names = ['fdrake', 'eric.araujo', 'dwayne', 'mkindahl', 'lukasz.langa']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue7005'
    versions = ['Python 2.7', 'Python 3.2']

    @mkindahl
    Copy link
    Mannequin Author

    mkindahl mannequin commented Sep 27, 2009

    When ConfigParser is used to read in a my.cnf file (MySQL Server
    Configuration File), it fails for options that do not have value.

    ConfigParser is designed to require a value for each option, but some
    systems, such as MySQL option file reader, accepts options without
    values. Reading a my.cnf file is almost certain to include options
    without values. The server can accept options with values even though
    the value is not necessary, but there are some tools that do not allow
    values for options that do not require them.

    There is an attached patch that optionally will allow options to not
    have a value. In order to distinguish options with no value from options
    with the empty string, None is assigned to options without values.

    The default behavior is to not allow options without values.

    @mkindahl mkindahl mannequin added the stdlib Python modules in the Lib dir label Sep 27, 2009
    @freddrake
    Copy link
    Member

    The test "value is not None" in line 620 (of the new version) could be
    just "value" and get a little more value from less code.

    I don't think I've ever run across a sample .ini-style file that used
    unspecified values, though it's frequently done in "flat" configuration
    files.

    Have you come across an existing configuration format that uses the
    [section] markers and unspecified values, or is this really a new use-case?

    @mkindahl
    Copy link
    Mannequin Author

    mkindahl mannequin commented Sep 28, 2009

    I replied to the mail, but I don't know if it is attached to the issue,
    so I'll repeat here.

    I'll change the "value is not None" to just "value" where I used that idiom.

    The style of using options without values is quite common in my.cnf
    files used by MySQL programs. For example, in the Debian (Ubuntu)
    package I have installed is using several options without values.

    @mkindahl
    Copy link
    Mannequin Author

    mkindahl mannequin commented Sep 28, 2009

    Fred L. Drake, Jr. wrote:

    Fred L. Drake, Jr. <fdrake@acm.org> added the comment:

    The test "value is not None" in line 620 (of the new version) could be
    just "value" and get a little more value from less code.

    OK.

    I don't think I've ever run across a sample .ini-style file that used
    unspecified values, though it's frequently done in "flat" configuration
    files.

    Have you come across an existing configuration format that uses the
    [section] markers and unspecified values, or is this really a new use-case?

    It is very common in my.cnf files for MySQL, and has been so "for ever." For
    example, the default my.cnf file that is installed on my Debian (Ubuntu) system
    have several options without values (e.g., skip-external-locking, quick, and
    quote-names).

    Best wishes,
    Mats Kindahl

    ----------


    Python tracker <report@bugs.python.org>
    <http://bugs.python.org/issue7005\>


    @mkindahl
    Copy link
    Mannequin Author

    mkindahl mannequin commented Sep 29, 2009

    Adding patch with the changes requested by Fred.

    @freddrake
    Copy link
    Member

    I just looked at some MySQL configuration examples, and wonder if the
    guys that made that configuration-style choice were on crack.

    MySQL's syntax is sufficient justification for this feature (however
    abhorrent I consider it).

    (I've not read the patch.)

    @mkindahl
    Copy link
    Mannequin Author

    mkindahl mannequin commented Nov 14, 2009

    So, what is the status on this?
    Who needs to review it?
    Is there anything I can do to get it accepted?
    Do I need to make any changes (in addition to those already suggested
    and done by fdrake)?

    @freddrake
    Copy link
    Member

    Assigning to myself for handling.

    Bumping to Python 2.7 / 3.2 since support for this syntax variation is a new feature.

    @freddrake freddrake self-assigned this Feb 17, 2010
    @freddrake
    Copy link
    Member

    Patch and documentation committed to the trunk (r78232).

    @freddrake
    Copy link
    Member

    Patch and documentation merged to the py3k branch (r78233).

    Work on this is complete.

    @freddrake freddrake added the type-feature A feature request or enhancement label Feb 19, 2010
    @dwayne
    Copy link
    Mannequin

    dwayne mannequin commented Aug 26, 2010

    This is causing a regression in our code.

    Previously when we write out our INI file for an entry that has a value of None we saw the following:
    value = None

    These are now stored as:
    value

    This is now causing a traceback in our code.

    But interestingly I haven't changed anything in our initialisation of ConfigParser, I would have assumed that I need to set allow_no_value for this to work in the new way that MySQL expects.

    I would have expected everything to work as it currently does in 2.6 unless I specifically request

    You can see the traceback of Virtaal under Python 2. in this bug:
    https://bugzilla.redhat.com/show_bug.cgi?id=622061

    @freddrake
    Copy link
    Member

    Re-opening for investigation.

    (The previous message really should have been a new issue.)

    @freddrake freddrake reopened this Aug 26, 2010
    @ambv
    Copy link
    Contributor

    ambv commented Sep 2, 2010

    This one is strange. Trying to set a None value through set() raises 'TypeError: option values must be strings' on both Python 3.2 and 2.7. A string value of 'None' behaves as expected (e.g. correctly).

    @freddrake
    Copy link
    Member

    I've attached a diagnostic script that I ran with Python 2.4..3.2 (current py3k HEAD); there are two output variants:

    "old style":

    [section]
    option = None
    

    "new style":

    [section]
    option
    

    This is the output I get when running this script for each of those Python versions:

    2.4.6 RawConfigParser: old-style output
    2.4.6 SafeConfigParser: raised TypeError on set
    2.4.6 ConfigParser: old-style output
    
    2.5.5 RawConfigParser: old-style output
    2.5.5 SafeConfigParser: raised TypeError on set
    2.5.5 ConfigParser: old-style output
    
    2.6.5 RawConfigParser: old-style output
    2.6.5 SafeConfigParser: raised TypeError on set
    2.6.5 ConfigParser: old-style output
    
    2.7 RawConfigParser: new-style output
    2.7 SafeConfigParser: raised TypeError on set
    2.7 ConfigParser: new-style output
    
    3.1.1 RawConfigParser: old-style output
    3.1.1 SafeConfigParser: raised TypeError on set
    3.1.1 ConfigParser: old-style output
    
    3.2a1+ RawConfigParser: new-style output
    3.2a1+ SafeConfigParser: raised TypeError on set
    3.2a1+ ConfigParser: new-style output
    

    Essentially: For the RawConfigParser and ConfigParser classes, the output changes in 2.7 and 3.2, and in a way that should be considered incorrect because it conflicts with the allow_no_values setting.

    This is a bug and should be fixed in both 2.7 and 3.2.

    The TypeError-on-set is consistently raised only for SafeConfigParser, and should remain unchanged. (Why this was handled differently for SafeConfigParser I don't recall offhand.)

    @freddrake
    Copy link
    Member

    Attached fix & test for Python 2; adjusting to Python 3 is trivial.

    The test could be added to 2.6 as well to protect against regressions there, though that's unlikely to be a significant issue.

    @freddrake
    Copy link
    Member

    Commited as r84443 (release27-maint), r84444 (py3k)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants