config
config copied to clipboard
Substituting environment variables fails when merging objects
The following typesafe config loads just fine (i.e., working will be set to {b = value}
):
a {
default = {}
working = ${a.default} {
b = value
}
}
When adding an environment override for b, loading the config will blow up:
a {
default = {}
problem = ${a.default} {
b = value
b = ${?VAR}
}
}
With the following exception:
Exception in thread "main" com.typesafe.config.ConfigException$BugOrBroken: SimpleConfigObject.replaceChild did not find SimpleConfigObject({"b":"value","b":${?VAR}}) in SimpleConfigObject({"default":{},"problem":${a.default}{"b":"value","b":${?VAR}}})
Note: this works with version 1.2.1, but fails with more recent versions.
Thanks - my memory of this part of the code is fuzzy but I think replaceChild might encounter a list of unmerged objects and need to recurse into it to find the thing to replace. Could potentially be straightforward.
I thought giving it a shot for the past hour or so but I can't make it work :(. Anyway, at least I can confirm that the list of objects encountered in replaceChild is indeed formed by unmerged objects at some point (it has a ConfigConcatenation
object containing the stuff we would need to recurse into I assume).
I'll give it another shot if I have some spare time next week, thanks
These 3 issues seem to be related https://github.com/lightbend/config/issues/356 https://github.com/lightbend/config/issues/378
Leaving in case this is biting anyone that needs a workaround. One of my coworkers (@sruthivasireddy) discovered that the following seems to allow the introduction of defaults overridden by environment variable.
a {
default = {}
b_default = {
b = value
b = ${?VAR}
}
problem = ${a.default} ${a.b_default} {
c = value
}
}
How this doesn't also tickle the problem seems odd but working code is working code.
@LannyRipple Thank you! This solved my issue!