Open SZiesche opened 9 months ago
Indeed, it shouldn't crash if it can't find the node when a default value is provided.
to make this more precise, I would like to have the following script pass.
from dataclasses import dataclass
from omegaconf import OmegaConf, II
cfg1 = OmegaConf.create({"a": "${oc.select:..member, 5}"})
print(cfg1.a) # this raises an Error because of the missing node
@dataclass
class Config:
a: int = II("${oc.select:..member, 5}")
cfg2 = OmegaConf.structured(Config)
print(cfg2.a) # this raises an Error too
Is your feature request related to a problem? Please describe. By using
oc.select
we can define default values if the interpolation target is not found. However, the "not found" part is not very robust. For example, if we refer to a non-existing node, we still raise an error.Consider for example the case, where we have a config, that is usually nested in some other config and has a member like
my_member: int = ${oc.select:..member, 5}
that is by default inherited from the parent. Now we want to test this config standalone or we want to use it in a different context were the parent doesn't exist, then the code just crashes.Describe the solution you'd like It would be cool to turn this off or to give the user an option to turn this off. For example, we could change the select implementation to
Describe alternatives you've considered Alternatively, we could add a flag like
throw_on_node_not_existing
to the function and raise the error depending on that value. Then the users could relatively easy write their own robust select method.