chimpler / pyhocon

HOCON parser for Python
Apache License 2.0
508 stars 121 forks source link

substitution resulting in cycle in pyhocon==0.3.60 (works in 0.3.59) #300

Open DannyVarod opened 1 year ago

DannyVarod commented 1 year ago

Recreation:

local.conf:

conf: {
  kafka_config: {
    # added quotes here so that the keys won't be split into objects on dots
    # i.e. bootstrap.servers=value not bootstrap { servers=value }
    # keys are unquoted by code in ConfigLoader
    "bootstrap.servers": "kafka:9092"
  }
  kafka_producer_config: ${conf.kafka_config}
  kafka_producer_config: {
    "request.timeout.ms": 30000
    "connections.max.idle.ms": 1800000
  }
}

env-overrides.conf (in same folder as above file):

include "local.conf"

conf: {
  kafka_config: {
    "bootstrap.servers": "other-kafka:9092"
  }
  kafka_producer_config: ${conf.kafka_config}
  kafka_producer_config: ${conf.kafka_producer_config}
}

Python code:

ConfigFactory.parse_file('path_to_env-overrides.conf')

Error:

in load
config = ConfigFactory.parse_file(str(override_path))
File "/usr/local/lib/python3.7/site-packages/pyhocon/config_parser.py", line 142, in parse_file
return cls.parse_string(content, os.path.dirname(filename), resolve, unresolved_value)
File "/usr/local/lib/python3.7/site-packages/pyhocon/config_parser.py", line 192, in parse_string
return ConfigParser().parse(content, basedir, resolve, unresolved_value)
File "/usr/local/lib/python3.7/site-packages/pyhocon/config_parser.py", line 460, in parse
has_unresolved = cls.resolve_substitutions(config, allow_unresolved)
File "/usr/local/lib/python3.7/site-packages/pyhocon/config_parser.py", line 699, in resolve_substitutions
col=col(substitution.loc, substitution.instring)) for substitution in substitutions)))
pyhocon.exceptions.ConfigSubstitutionException: Cannot resolve ${conf.kafka_consumer_config}: (line: 12, col: 26), ${conf.kafka_producer_config}: (line: 14, col: 26). Check for cycles.