From ea07ed008fe896b8c9812bd14785dbfa4fca0679 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Thu, 30 Jul 2020 20:18:07 +0300 Subject: [PATCH] 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 --- action/config_template.py | 20 ++++++++----------- tests/files/test_comment_configs.ini.expected | 1 + tests/test.yml | 2 ++ 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/action/config_template.py b/action/config_template.py index 10f6ebb..3abfdc0 100644 --- a/action/config_template.py +++ b/action/config_template.py @@ -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: diff --git a/tests/files/test_comment_configs.ini.expected b/tests/files/test_comment_configs.ini.expected index 652b879..1de6856 100644 --- a/tests/files/test_comment_configs.ini.expected +++ b/tests/files/test_comment_configs.ini.expected @@ -33,6 +33,7 @@ test = test1,test2 testopt1 = 9000 # This is another test opt #testop2 = over 9000 +testop2 = below 9000 [TestSection] things = stuff diff --git a/tests/test.yml b/tests/test.yml index 2e01a85..d9bbccb 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -181,6 +181,8 @@ - test2 TestSection: things: stuff + SubSection: + testop2: below 9000 diff_ini: added: DEFAULT: