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

Cannot create 'default' section #80

Open
kevingunn-wk opened this issue Aug 17, 2021 · 1 comment
Open

Cannot create 'default' section #80

kevingunn-wk opened this issue Aug 17, 2021 · 1 comment

Comments

@kevingunn-wk
Copy link

When running crudini with the --set flag, I'm unable to create a default section.

Command:
crudini --set file.conf default name value

Result:

Traceback (most recent call last):
  File "/usr/local/bin/crudini", line 979, in <module>
    sys.exit(main())
  File "/usr/local/bin/crudini", line 975, in main
    return crudini.run()
  File "/usr/local/bin/crudini", line 881, in run
    self.command_set()
  File "/usr/local/bin/crudini", line 731, in command_set
    self.set_name_value(self.section, self.param, self.value)
  File "/usr/local/bin/crudini", line 708, in set_name_value
    self.conf.add_section(section)
  File "/usr/local/lib/python3.9/site-packages/iniparse/compat.py", line 62, in add_section
    raise ValueError('Invalid section name: %s' % section)
ValueError: Invalid section name: default

However, if I modify the command, it succeeeds:
crudini --set file.conf defaults name value

File contents:

[defaults]
name = value

If a default section exists, then the command seems to work just fine, but fails when creating a new file when a default section does not yet exist.

@pixelb
Copy link
Owner

pixelb commented Aug 17, 2021

Indeed :(

This looks to be an issue in iniparse.
It doesn't treat "default" specially when reading, so I don't know why it's restricting creation of such a section.
I guess it's for compat with other parsers.
I see ConfigParser has similar restrictions, so I guess it's trying to avoid compat issues with it:
https://stackoverflow.com/questions/25628651/write-to-lowercase-default-section-configparser/52217359
I also see iniparse hardcodes "default" rather than using its DEFAULTSECT definition.

As a workaround we could check case variations of "default" and change to "default_crudini_remove_when_writing".
We already do similar string replacements on write.

I'll need to look into compat issues though a bit, before doing this

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

No branches or pull requests

2 participants