chimpler / pyhocon

HOCON parser for Python
Apache License 2.0
502 stars 118 forks source link

Nested config resolving broken with 0.3.60 #320

Closed fsonntag closed 8 months ago

fsonntag commented 8 months ago

Given this config and it's parsing:

from pyhocon import ConfigFactory

if __name__ == '__main__':
    c = """
        args = "A"

        job_args: ${nested-args}

        nested-args {
          norm: ${?args}
        }

        job_args: ${nested-args}

        nested-args {
          norm: ${?args}
        }
    """
    config = ConfigFactory.parse_string(c)
    inner_config = config.get('job_args')
    print(inner_config)
    config.as_plain_ordered_dict()

It's producing this output with 0.3.60:

ConfigTree([('norm', [ConfigValues: [ConfigSubstitution: args]])])
Traceback (most recent call last):
  File "/.../config_t.py", line 22, in <module>
    config.as_plain_ordered_dict()
  File "/.../venv/lib/python3.8/site-packages/pyhocon/config_tree.py", line 455, in as_plain_ordered_dict
    return OrderedDict((key.strip('"'), plain_value(value)) for key, value in self.items())
  File "/.../venv/lib/python3.8/site-packages/pyhocon/config_tree.py", line 455, in <genexpr>
    return OrderedDict((key.strip('"'), plain_value(value)) for key, value in self.items())
  File "/.../venv/lib/python3.8/site-packages/pyhocon/config_tree.py", line 449, in plain_value
    return v.as_plain_ordered_dict()
  File "/.../venv/lib/python3.8/site-packages/pyhocon/config_tree.py", line 455, in as_plain_ordered_dict
    return OrderedDict((key.strip('"'), plain_value(value)) for key, value in self.items())
  File "/.../venv/lib/python3.8/site-packages/pyhocon/config_tree.py", line 455, in <genexpr>
    return OrderedDict((key.strip('"'), plain_value(value)) for key, value in self.items())
  File "/.../venv/lib/python3.8/site-packages/pyhocon/config_tree.py", line 452, in plain_value
    raise ConfigException("The config tree contains unresolved elements")
pyhocon.exceptions.ConfigException: The config tree contains unresolved elements

With 0.3.59 it's working fine:

ConfigTree([('norm', 'A')])

It seems to be introduced with this change: https://github.com/chimpler/pyhocon/pull/287

fsonntag commented 8 months ago

Realized that it also doesn't work in the Java implementation... so I guess we were lucky before