Issue 32108: configparser bug: section is emptied if you assign a section to itself (original) (raw)

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/76289

classification

Title: configparser bug: section is emptied if you assign a section to itself
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6

process

Status: closed Resolution: fixed
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 2022-04-11 14:58 by admin. This issue is now closed.

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
2022-04-11 14:58:54 admin set github: 76289
2019-02-17 01:34:39 cheryl.sabella set status: open -> closedresolution: fixedstage: patch review -> resolved
2018-06-12 20:37:57 lukasz.langa set messages: +
2018-06-10 16:33:41 cheryl.sabella set pull_requests: + <pull%5Frequest7210>
2018-04-17 21:51:07 lukasz.langa set messages: + versions: + Python 3.6, Python 3.7, Python 3.8, - Python 3.5
2017-11-28 15:43:05 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2017-11-28 11:01:03 corona10 set nosy: + corona10
2017-11-28 10:54:36 corona10 set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest4523>
2017-11-21 20:05:44 lukasz.langa set messages: +
2017-11-21 18:43:15 r.david.murray set nosy: + lukasz.langa
2017-11-21 17:46:10 simonltwick create