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

String values cannot contain $ #48

Closed
MartinBernstorff opened this issue Nov 17, 2023 · 4 comments · Fixed by #49
Closed

String values cannot contain $ #48

MartinBernstorff opened this issue Nov 17, 2023 · 4 comments · Fixed by #49
Labels
bug Something isn't working

Comments

@MartinBernstorff
Copy link

MartinBernstorff commented Nov 17, 2023

Minimal example:

from confection import Config

config_str = """[section]
value='^test$'
"""

Config().from_str(config_str)

Would love to be able to have regex strings in my config, e.g. for using polars.exclude to filter columns.

Raises:

InterpolationSyntaxError
'$' must be followed by '$' or '{', found: '$'
  File "C:\Users\adminmanber\Desktop\psycop-common\psycop\common\model_training_v2\config\config_utils.py", line 33, in <module>
    Config().from_str(config_str)
configparser.InterpolationSyntaxError: '$' must be followed by '$' or '{', found: '$'
@adrianeboyd adrianeboyd added the bug Something isn't working label Nov 20, 2023
@adrianeboyd
Copy link
Contributor

Thanks for the report!

If it worked as intended, I think that $$ should work here as the escaped form of $ in the configparser format.

I haven't looked into the gory details, but it initially looks like it's being interpolated more than once, which causes problems with $$.

A terrible hacky workaround for this one specific problem:

[section]
value="^test$$$$"

The interpolated config then looks like this, where this string does still work as the intended regex:

[section]
value = "^test$$"

@MartinBernstorff
Copy link
Author

Ah, I see, thanks! Hadn't noticed that configparser was part of stdlib, glad to see it!

This appears to be a bug in configparser, then?

@adrianeboyd
Copy link
Contributor

No, we've overridden some of the interpolation with custom methods, so I think it's a bug in confection.

@adrianeboyd
Copy link
Contributor

Ah, the problem isn't directly in the parsing/interpolation, it's in the to_str conversion that doesn't re-escape $ in its own output.

@adrianeboyd adrianeboyd linked a pull request Nov 20, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants