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

Optional substitution from included config not working #314

Open
fsonntag opened this issue Sep 1, 2023 · 0 comments
Open

Optional substitution from included config not working #314

fsonntag opened this issue Sep 1, 2023 · 0 comments

Comments

@fsonntag
Copy link

fsonntag commented Sep 1, 2023

I noticed an issue that I can not substitute twice in an included config. See the following example:

base.conf:

submit_user = "dev"
submit_user = ${?USER}
submit_user = ${?USERNAME}

other.conf

include "base.conf"

Python code:

import os

os.environ["USER"] = "test"
from pyhocon import ConfigFactory

config = ConfigFactory.parse_file("base.conf")
print(config["submit_user"])  # works as expected
config = ConfigFactory.parse_file("other.conf")
print(config["submit_user"])  # fails

Stacktrace:

Traceback (most recent call last):
  File "/.../config_test.py", line 10, in <module>
    print(config["submit_user"])  # fails
  File "/.../config_tree.py", line 393, in __getitem__
    val = self.get(item)
  File "/.../config_tree.py", line 236, in get
    return self._get(ConfigTree.parse_key(key), 0, default)
  File "/.../config_tree.py", line 176, in _get
    raise ConfigMissingException(
pyhocon.exceptions.ConfigMissingException: 'No configuration setting found for key submit_user'

Removing the second substitution submit_user = ${?USERNAME} makes it work again though. It's not expected behavior, since the statement should be ignored if nothing is being set.

I tried digging into the code to fix it, but could not figure it out. Happy to help if someone has some hints.

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

1 participant