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 bug: section is emptied if you assign a section to itself #76289

Closed
simonltwick mannequin opened this issue Nov 21, 2017 · 5 comments
Closed

configparser bug: section is emptied if you assign a section to itself #76289

simonltwick mannequin opened this issue Nov 21, 2017 · 5 comments
Labels
3.7 (EOL) end of life 3.8 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@simonltwick
Copy link
Mannequin

simonltwick mannequin commented Nov 21, 2017

BPO 32108
Nosy @ambv, @serhiy-storchaka, @corona10
PRs
  • bpo-32108: Fix configparser when a section is assigned to itself. #4607
  • bpo-32108: Don't clear configparser values if key is assigned to itself #7588
  • 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 = None
    closed_at = <Date 2019-02-17.01:34:39.553>
    created_at = <Date 2017-11-21.17:46:10.957>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'configparser bug: section is emptied if you assign a section to itself'
    updated_at = <Date 2019-02-17.01:34:39.553>
    user = 'https://bugs.python.org/simonltwick'

    bugs.python.org fields:

    activity = <Date 2019-02-17.01:34:39.553>
    actor = 'cheryl.sabella'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-02-17.01:34:39.553>
    closer = 'cheryl.sabella'
    components = ['Library (Lib)']
    creation = <Date 2017-11-21.17:46:10.957>
    creator = 'simonltwick'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32108
    keywords = ['patch']
    message_count = 5.0
    messages = ['306675', '306682', '307131', '315425', '319400']
    nosy_count = 4.0
    nosy_names = ['lukasz.langa', 'serhiy.storchaka', 'simonltwick', 'corona10']
    pr_nums = ['4607', '7588']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue32108'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @simonltwick
    Copy link
    Mannequin Author

    simonltwick mannequin commented Nov 21, 2017

    If you assign a ConfigParser section back to the parent ConfigParser object (say after updating the section), the section is emptied.

    (I realise now that you don't need to assign the section back to the parent as it's a proxy for the section in the parent already - but still it does not behave as you would expect):
    code:
    from configparser import ConfigParser
    config = ConfigParser()
    config['test'] = {'key': 'value'}
    section = config['test']
    section['key'] = 'different'
    print("before: config['test'] is %s" % dict(config['test']))
    config['test'] = section
    print("after: config['test'] is %s" % dict(config['test']))
    # the section is now printed as {}

    @simonltwick simonltwick mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Nov 21, 2017
    @ambv
    Copy link
    Contributor

    ambv commented Nov 21, 2017

    Confirmed.

    @serhiy-storchaka
    Copy link
    Member

    PR 4607 doesn't look a correct solution to me. I don't know a precedence of calling deepcopy() for a value in __setitem__(). deepcopy() is too heavy, calling it can slow down normal cases. Using deepcopy likely means a bad design.

    @ambv
    Copy link
    Contributor

    ambv commented Apr 17, 2018

    I agree, the fix needs to be changed. What we probably want is to discover this kind of assignment and special-case *that*.

    @ambv ambv added 3.7 (EOL) end of life 3.8 (EOL) end of life labels Apr 17, 2018
    @ambv
    Copy link
    Contributor

    ambv commented Jun 12, 2018

    New changeset 33cd058 by Łukasz Langa (Cheryl Sabella) in branch 'master':
    bpo-32108: Don't clear configparser values if key is assigned to itself (GH-7588)
    33cd058

    @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
    3.7 (EOL) end of life 3.8 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants