You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
defselect_value(
cfg: Container,
key: str,
*,
default: Any=_DEFAULT_MARKER_,
throw_on_resolution_failure: bool=True,
throw_on_missing: bool=False,
absolute_key: bool=False,
) ->Any:
try: # this try/except block is new, the rest stays the same.node=select_node(
cfg=cfg,
key=key,
throw_on_resolution_failure=throw_on_resolution_failure,
throw_on_missing=throw_on_missing,
absolute_key=absolute_key,
)
exceptConfigKeyErrorase:
node=Nonenode_not_found=nodeisNoneifnode_not_foundornode._is_missing():
ifdefaultisnot_DEFAULT_MARKER_:
returndefaultelse:
returnNonereturn_get_value(node)
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.
The text was updated successfully, but these errors were encountered:
to make this more precise, I would like to have the following script pass.
fromdataclassesimportdataclassfromomegaconfimportOmegaConf, IIcfg1=OmegaConf.create({"a": "${oc.select:..member, 5}"})
print(cfg1.a) # this raises an Error because of the missing node@dataclassclassConfig:
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.The text was updated successfully, but these errors were encountered: