diff --git a/news/364.bugfix b/news/364.bugfix new file mode 100644 index 000000000..18dce42e7 --- /dev/null +++ b/news/364.bugfix @@ -0,0 +1 @@ +Properly crash when accessing `${foo.bar}` if `foo` is a value node (instead of silently returning `${foo}`) diff --git a/omegaconf/base.py b/omegaconf/base.py index 4dec6fc11..dcbba0d52 100644 --- a/omegaconf/base.py +++ b/omegaconf/base.py @@ -252,7 +252,6 @@ def _select_impl( :param key: :return: """ - from . import ValueNode from .omegaconf import _select_one if key == "": @@ -277,9 +276,6 @@ def _select_impl( throw_on_resolution_failure=throw_on_resolution_failure, ) - if isinstance(ret, ValueNode): - return ret._get_parent(), k, ret - assert ret is None or isinstance(ret, Container) root = ret diff --git a/tests/test_interpolation.py b/tests/test_interpolation.py index a7c79fe8f..7193e52f2 100644 --- a/tests/test_interpolation.py +++ b/tests/test_interpolation.py @@ -394,6 +394,12 @@ def test_merge_with_interpolation() -> None: OmegaConf.merge(cfg, {"typed_bar": "nope"}) +def test_non_container_interpolation() -> None: + cfg = OmegaConf.create(dict(foo=0, bar="${foo.baz}")) + with pytest.raises(AssertionError): + cfg.bar + + def test_indirect_interpolation() -> None: d = { "a": {"aa": 10}, @@ -414,7 +420,7 @@ def test_indirect_interpolation2() -> None: d = { "a": {"aa": 10}, "b": "${a.aa}", - "c": "${b.aa}", + "c": "${b}", } cfg = OmegaConf.create(d)