Fix section overrides when commented option persist

In cases, when key already exist, but commented out without space
(ie "#key) and is not in default section, it's not updated with
sectdict.insert statement. That is possible happens because
self._sections keys are protected and can't be overwritten (at least
new assignment makes no difference)

Change-Id: Ie0c588a2d559bd38c68b3d018e547a036d83214c
Closes-Bug: #1889547
This commit is contained in:
Dmitriy Rabotyagov 2020-07-30 20:18:07 +03:00
parent 4ed672e399
commit ea07ed008f
3 changed files with 11 additions and 12 deletions

View File

@ -204,19 +204,15 @@ class ConfigTemplateParser(ConfigParser.RawConfigParser):
use_defaults = False
option = self.optionxform(option)
try:
index = sectdict.index('#%s' % option)
except (ValueError, IndexError):
sectdict[option] = value
else:
if use_defaults:
self._defaults = sectdict.insert(index, option, value)
if use_defaults:
try:
index = sectdict.index('#%s' % option)
except (ValueError, IndexError):
sectdict[option] = value
else:
self._sections[section] = sectdict.insert(
index,
option,
value
)
self._defaults = sectdict.insert(index, option, value)
else:
sectdict[option] = value
def _write(self, fp, section, key, item, entry):
if section:

View File

@ -33,6 +33,7 @@ test = test1,test2
testopt1 = 9000
# This is another test opt
#testop2 = over 9000
testop2 = below 9000
[TestSection]
things = stuff

View File

@ -181,6 +181,8 @@
- test2
TestSection:
things: stuff
SubSection:
testop2: below 9000
diff_ini:
added:
DEFAULT: