classification
Title: configparser bug: section is emptied if you assign a section to itself
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: corona10, lukasz.langa, serhiy.storchaka, simonltwick
Priority: normal Keywords: patch

Created on 2017-11-21 17:46 by simonltwick, last changed 2018-06-12 20:37 by lukasz.langa.

Pull Requests
URL Status Linked Edit
PR 4607 closed corona10, 2017-11-28 10:54
PR 7588 merged cheryl.sabella, 2018-06-10 16:33
Messages (5)
msg306675 - (view) Author: Simon Lambourn (simonltwick) Date: 2017-11-21 17:46
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 {}
msg306682 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2017-11-21 20:05
Confirmed.
msg307131 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-11-28 15:43
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.
msg315425 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2018-04-17 21:51
I agree, the fix needs to be changed. What we probably want is to discover this kind of assignment and special-case *that*.
msg319400 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2018-06-12 20:37
New changeset 33cd058f21d0673253c88cea70388282918992bc by Łukasz Langa (Cheryl Sabella) in branch 'master':
bpo-32108: Don't clear configparser values if key is assigned to itself (GH-7588)
https://github.com/python/cpython/commit/33cd058f21d0673253c88cea70388282918992bc
History
Date User Action Args
2018-06-12 20:37:57lukasz.langasetmessages: + msg319400
2018-06-10 16:33:41cheryl.sabellasetpull_requests: + pull_request7210
2018-04-17 21:51:07lukasz.langasetmessages: + msg315425
versions: + Python 3.6, Python 3.7, Python 3.8, - Python 3.5
2017-11-28 15:43:05serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg307131
2017-11-28 11:01:03corona10setnosy: + corona10
2017-11-28 10:54:36corona10setkeywords: + patch
stage: patch review
pull_requests: + pull_request4523
2017-11-21 20:05:44lukasz.langasetmessages: + msg306682
2017-11-21 18:43:15r.david.murraysetnosy: + lukasz.langa
2017-11-21 17:46:10simonltwickcreate