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

[BUG] add_implicit_resolver() - use of "first" argument required?! #25

Closed
ghost opened this issue Jun 30, 2022 · 2 comments · Fixed by #29
Closed

[BUG] add_implicit_resolver() - use of "first" argument required?! #25

ghost opened this issue Jun 30, 2022 · 2 comments · Fixed by #29
Assignees
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Jun 30, 2022

Describe the bug
parse_config() uses this code to decide which YAML entries to actually look at: loader.add_implicit_resolver(tag, pattern, None) The third parameter, first, is intentionally set to None. However, if one takes a look at the YAML documentation, this exact argument controls whether a YAML entry should be looked at.

And indeed, it does not matter which value is passed as tag, as it will only be used to tag the entries and process them. But all entries will be processed, prefixed with the tag or not. As soon as first is also set to the value of tag, things start to work as expected: loader.add_implicit_resolver(tag, pattern, tag)

To Reproduce
Steps to reproduce the behavior:

  1. Add a prefixed and a non-prefixed environment variable substitution attempt to a YAML file, e. g.:
test:
  with-prefix: !ENV ${DPT_EXISTING_ENV}
  without-prefix: ${DPT_EXISTING_ENV}
  1. Try to use parse_config() on this YAML file, with tag set to different values as well as None.
  2. Each time both entries will be acted upon, as there is no first set and the pattern matches.

Expected behavior
Only the entries prefixed with the tag should be acted upon.

Additional context
Add any other context about the problem here.

  • Python version: 3.6 (sadly)
  • OS: Debian Buster
  • pyaml_env: 1.1.5
@ghost ghost added the bug Something isn't working label Jun 30, 2022
@ghost ghost assigned mkaranasou Jun 30, 2022
@mkaranasou
Copy link
Owner

@frank-straetz many thanks for the detailed issue and for pinpointing the cause.
loader.add_implicit_resolver(tag, pattern, first=[tag]) works as expected and parses only the lines that have a tag prefix.

I can prepare a PR for this.

@mkaranasou
Copy link
Owner

PR ready.

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.

1 participant