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

Unable to save Config with * args to str/disk #52

Open
HLasse opened this issue Dec 4, 2023 · 2 comments
Open

Unable to save Config with * args to str/disk #52

HLasse opened this issue Dec 4, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@HLasse
Copy link

HLasse commented Dec 4, 2023

Hi!

As part of my workflow, I want to save my Config to disk so I can reload it later. However, if the config contains a * section this fails.

Minimal example:

from confection import Config

test_cfg = """[test]
foo = bar

[test.*]
bar = foo
"""

cfg = Config().from_str(test_cfg)

cfg.to_str()

This results in

File "e:\lasse\test\psycop-common\test_confection.py", line 12, in <module>
    cfg.to_str()
  File "E:\ProgramData\Anaconda3\envs\psycop-main\lib\site-packages\confection\__init__.py", line 419, in to_str
    flattened.set(section_name, key, try_dump_json(value, node))
  File "E:\ProgramData\Anaconda3\envs\psycop-main\lib\configparser.py", line 1205, in set
    super().set(section, option, value)
  File "E:\ProgramData\Anaconda3\envs\psycop-main\lib\configparser.py", line 903, in set
    raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'test.*'

Tested on Windows and MacOS, using confection 0.1.3 and 0.1.4

@KennethEnevoldsen
Copy link
Contributor

Converting it to [test.*.value] solves the issue.

However unsure if that is the desired functionality. If it is it might be worth adding a check to see if any section ends with a * if it isn't the desired functionality.

@svlandeg
Copy link
Member

it might be worth adding a check to see if any section ends with a *

Yea, I think that's probably the best solution for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants