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

ConfigParser chokes on conflict markers in stdin and throws AttributeError #126541

Open
myxoid opened this issue Nov 7, 2024 · 4 comments
Open
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@myxoid
Copy link

myxoid commented Nov 7, 2024

Bug report

Bug description:

This is probably a duplicate of bug 107625, but I do not have a recent enough version of Python to check the behaviour.

Whether it is worth specially detecting conflict markers is something the code owners can decide.

To reproduce:

/tmp/py:

#!/usr/bin/python3

import configparser
import sys

sl = configparser.ConfigParser(allow_no_value=True)
sl.read_file(sys.stdin)

/tmp/z:

[list]
<<<<<<<< HEAD   (f12435 blah)
 foo
|||||||| BASE
 bar
========
 baz
>>>>>>>> CHANGE (faa768 blah)
$ </tmp/z /tmp/py
Traceback (most recent call last):
  File "/tmp/py", line 7, in <module>
    sl.read_file(sys.stdin)
  File "/usr/lib/python3.11/configparser.py", line 734, in read_file
    self._read(f, source)
  File "/usr/lib/python3.11/configparser.py", line 1077, in _read
    cursect[optname].append(value)
    ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'append'

Notes:

  • sys.stdin seems to be needed to trigger this - deserves further investigation because it may point to a bad assumption or similar in the parser
  • allow_no_value is needed to trigger this

Finger of blame:

            if (cursect is not None and optname and
                cur_indent_level > indent_level):
                cursect[optname].append(value)

This does not check that cursect[optname] is present.

CPython versions tested on:

3.10, 3.11, 3.12

Operating systems tested on:

Linux

@myxoid myxoid added the type-bug An unexpected behavior, bug, or error label Nov 7, 2024
@picnixz picnixz added the stdlib Python modules in the Lib dir label Nov 7, 2024
@picnixz
Copy link
Contributor

picnixz commented Nov 7, 2024

While it's similar to #107625, I wouldn't count this as a duplicate since it fails on a different input. So this is a legitimate bug report (if it happens on 3.12, then it likely happens on 3.13+ as well).

@ritvikpasham
Copy link
Contributor

Hi, is it already if I investigate this bug?

@picnixz
Copy link
Contributor

picnixz commented Nov 7, 2024

Go ahead! Thank you in advance!

@myxoid
Copy link
Author

myxoid commented Nov 8, 2024

The more general description of the problem should be "chokes on differing indentation". Here is an even simpler example:

[list]
 foo
  bar
 baz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants