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

gh-116957: configparser: Do post-process values after DuplicateOptionError #116958

Merged
merged 2 commits into from
Mar 19, 2024

Conversation

drothlis
Copy link
Contributor

@drothlis drothlis commented Mar 18, 2024

If you catch DuplicateOptionError / DuplicateSectionError when reading a config file (the intention is to skip invalid config files) and then attempt to use the ConfigParser instance, any values it had read successfully so far, were stored as a list instead of string! Later get calls would raise "AttributeError: 'list' object has no attribute 'find'" from somewhere deep in the interpolation code.

Fixes #116957.

…OptionError

If you catch DuplicateOptionError / DuplicateSectionError when reading a
config file (the intention is to skip invalid config files) and then
attempt to use the ConfigParser instance, any values it *had* read
successfully so far, were stored as a list instead of string! Later
`get` calls would raise "AttributeError: 'list' object has no attribute
'find'" from somewhere deep in the interpolation code.
@drothlis
Copy link
Contributor Author

This diff is best viewed with "ignore whitespace changes".

@drothlis
Copy link
Contributor Author

Without this fix, the new test fails like this:

======================================================================
ERROR: test_get_after_duplicate_option_error (__main__.ConfigParserTestCaseExtendedInterpolation.test_get_after_duplicate_option_error)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/drothlis/work/python/cpython/Lib/test/test_configparser.py", line 662, in test_get_after_duplicate_option_error
    self.assertEqual(cf.get('Foo', 'x'), '1')
                     ~~~~~~^^^^^^^^^^^^
  File "/home/drothlis/work/python/cpython/Lib/configparser.py", line 743, in get
    return self._interpolation.before_get(self, section, option, value,
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                          d)
                                          ^^
  File "/home/drothlis/work/python/cpython/Lib/configparser.py", line 441, in before_get
    self._interpolate_some(parser, option, L, value, section, defaults, 1)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/drothlis/work/python/cpython/Lib/configparser.py", line 458, in _interpolate_some
    p = rest.find("$")
        ^^^^^^^^^
AttributeError: 'list' object has no attribute 'find'

======================================================================
FAIL: test_get_after_duplicate_option_error (__main__.StrictTestCase.test_get_after_duplicate_option_error)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/drothlis/work/python/cpython/Lib/test/test_configparser.py", line 662, in test_get_after_duplicate_option_error
    self.assertEqual(cf.get('Foo', 'x'), '1')
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: ['1'] != '1'

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@serhiy-storchaka serhiy-storchaka added needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes and removed needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels Mar 19, 2024
@serhiy-storchaka serhiy-storchaka merged commit b1bc375 into python:main Mar 19, 2024
39 checks passed
@serhiy-storchaka serhiy-storchaka added needs backport to 3.11 only security fixes needs backport to 3.12 bug and security fixes labels Mar 19, 2024
@miss-islington-app
Copy link

Thanks @drothlis for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @drothlis for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

@miss-islington-app
Copy link

Sorry, @drothlis and @serhiy-storchaka, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker b1bc37597f0d36084c4dcb15977fe6d4b9322cd4 3.11

@miss-islington-app
Copy link

Sorry, @drothlis and @serhiy-storchaka, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker b1bc37597f0d36084c4dcb15977fe6d4b9322cd4 3.12

@drothlis drothlis deleted the fix-gh-116957 branch March 19, 2024 15:16
drothlis added a commit to drothlis/cpython that referenced this pull request Mar 19, 2024
…plicateOptionError (pythonGH-116958)

If you catch DuplicateOptionError / DuplicateSectionError when reading a
config file (the intention is to skip invalid config files) and then
attempt to use the ConfigParser instance, any values it *had* read
successfully so far, were stored as a list instead of string! Later
`get` calls would raise "AttributeError: 'list' object has no attribute
'find'" from somewhere deep in the interpolation code.
(cherry picked from commit b1bc375)

Co-authored-by: David Röthlisberger <david@rothlis.net>
@bedevere-app
Copy link

bedevere-app bot commented Mar 19, 2024

GH-117012 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.11 only security fixes label Mar 19, 2024
drothlis added a commit to drothlis/cpython that referenced this pull request Mar 19, 2024
…plicateOptionError (pythonGH-116958)

If you catch DuplicateOptionError / DuplicateSectionError when reading a
config file (the intention is to skip invalid config files) and then
attempt to use the ConfigParser instance, any values it *had* read
successfully so far, were stored as a list instead of string! Later
`get` calls would raise "AttributeError: 'list' object has no attribute
'find'" from somewhere deep in the interpolation code.
(cherry picked from commit b1bc375)

Co-authored-by: David Röthlisberger <david@rothlis.net>
@bedevere-app
Copy link

bedevere-app bot commented Mar 19, 2024

GH-117013 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Mar 19, 2024
ambv pushed a commit that referenced this pull request Mar 19, 2024
…eOptionError (GH-116958) (GH-117013)

If you catch DuplicateOptionError / DuplicateSectionError when reading a
config file (the intention is to skip invalid config files) and then
attempt to use the ConfigParser instance, any values it *had* read
successfully so far, were stored as a list instead of string! Later
`get` calls would raise "AttributeError: 'list' object has no attribute
'find'" from somewhere deep in the interpolation code.

(cherry picked from commit b1bc375)
ambv pushed a commit that referenced this pull request Mar 19, 2024
…eOptionError (GH-116958) (GH-117012)

If you catch DuplicateOptionError / DuplicateSectionError when reading a
config file (the intention is to skip invalid config files) and then
attempt to use the ConfigParser instance, any values it *had* read
successfully so far, were stored as a list instead of string! Later
`get` calls would raise "AttributeError: 'list' object has no attribute
'find'" from somewhere deep in the interpolation code.

(cherry picked from commit b1bc375)
vstinner pushed a commit to vstinner/cpython that referenced this pull request Mar 20, 2024
…OptionError (pythonGH-116958)

If you catch DuplicateOptionError / DuplicateSectionError when reading a
config file (the intention is to skip invalid config files) and then
attempt to use the ConfigParser instance, any values it *had* read
successfully so far, were stored as a list instead of string! Later
`get` calls would raise "AttributeError: 'list' object has no attribute
'find'" from somewhere deep in the interpolation code.
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
…OptionError (pythonGH-116958)

If you catch DuplicateOptionError / DuplicateSectionError when reading a
config file (the intention is to skip invalid config files) and then
attempt to use the ConfigParser instance, any values it *had* read
successfully so far, were stored as a list instead of string! Later
`get` calls would raise "AttributeError: 'list' object has no attribute
'find'" from somewhere deep in the interpolation code.
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
…OptionError (pythonGH-116958)

If you catch DuplicateOptionError / DuplicateSectionError when reading a
config file (the intention is to skip invalid config files) and then
attempt to use the ConfigParser instance, any values it *had* read
successfully so far, were stored as a list instead of string! Later
`get` calls would raise "AttributeError: 'list' object has no attribute
'find'" from somewhere deep in the interpolation code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

configparser.DuplicateOptionError leaves ConfigParser instance in bad state
2 participants