diff --git a/omegaconf/built_in_resolvers.py b/omegaconf/built_in_resolvers.py index f62d550d5..22426e45d 100644 --- a/omegaconf/built_in_resolvers.py +++ b/omegaconf/built_in_resolvers.py @@ -152,11 +152,17 @@ def _get_and_validate_dict_input( if isinstance(in_dict, str): # Path to an existing key in the config: use `select()`. key = in_dict + if key.startswith("."): + raise NotImplementedError( + f"To use relative interpolations with `{resolver_name}`, please use " + f"the explicit interpolation syntax: ${{{resolver_name}:${{{key}}}}}" + ) in_dict = OmegaConf.select( root, key, throw_on_missing=True, default=_DEFAULT_SELECT_MARKER_ ) if in_dict is _DEFAULT_SELECT_MARKER_: raise ConfigKeyError(f"Key not found: '{key}'") + assert in_dict is not None if not isinstance(in_dict, Mapping): raise TypeError( diff --git a/tests/interpolation/built_in_resolvers/test_dict.py b/tests/interpolation/built_in_resolvers/test_dict.py index a9cea43cc..17251ca19 100644 --- a/tests/interpolation/built_in_resolvers/test_dict.py +++ b/tests/interpolation/built_in_resolvers/test_dict.py @@ -104,6 +104,15 @@ def test_dict_keys(cfg: Any, key: Any, expected: Any) -> None: ), id="type_error_dictconfig", ), + param( + {"foo": "${oc.dict.keys_or_values:.bar}", "bar": {"x": 0}}, + "foo", + raises( + InterpolationResolutionError, + match=re.escape("NotImplementedError"), + ), + id="relative_with_select", + ), ], ) def test_get_and_validate_dict_input(