omry / omegaconf

Flexible Python configuration system. The last one you will ever need.
BSD 3-Clause "New" or "Revised" License
1.94k stars 105 forks source link

oc.decode resolver failing to parse "???" as MISSING #1059

Open guillermojp opened 1 year ago

guillermojp commented 1 year ago

Describe the bug

I have been trying to get some values from the envvars and I would like to have some default values in case the variable is not found. For that purpose, I've been using the missing value indicator ??? alongside oc.decode to retrieve any potential value, but the ??? is returned as a string and doesn't throw MissingMandatoryValue exception.

To Reproduce

>>> cfg = OmegaConf.create(
>>>     {
>>>         "my_key": "${oc.decode:${oc.env:MY_ENVVAR,???}}"
>>>     }
>>> )
>>> print(cfg.my_key)
???
>>> print(type(cfg.my_key)))
<class 'str'>

Expected behavior Accessing cfg.my_key should throw MissingMandatoryValue.

Additional context

kunaltyagi commented 1 year ago

Related: #762

The OmegaConf.resolve is a potential workaround