chimpler / pyhocon

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

Cannot resolve reference to nested variable #304

Open INRIX-Mark-Gershaft opened 1 year ago

INRIX-Mark-Gershaft commented 1 year ago

Found issue where Java implementation can resolve nested substitution, but this implementation gets confused because it doesn't expect reference to yet unresolved substitution.

Here is an example:

configuration.param1 = null

server = {
    serverName = "1234"
    user = "reader"
}

databaseRole = ${server}
databaseRole.databaseName = "XD_"${configuration.persistence.suffix}

configuration.persistence.suffix = "r1"
configuration.persistence.connection = ${databaseRole}

dataExport = {
    ssh = {
        host = ${configuration.persistence.connection.serverName} 
    }
}

What is very strange is that removal of declaration configuration.param1 results in successful resolution of all substitutions. However, with this declaration resolution crashes on configuration.persistence.connection.serverName with

raise ConfigWrongTypeException(
pyhocon.exceptions.ConfigWrongTypeException: configuration.persistence.connection has type ConfigValues rather than dict