Skip to content

Commit

Permalink
Properly crash when trying to access child of a value node
Browse files Browse the repository at this point in the history
  • Loading branch information
odelalleau committed Sep 9, 2020
1 parent bac94e0 commit 35ee3d7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/364.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Properly crash when accessing `${foo.bar}` if `foo` is a value node (instead of silently returning `${foo}`)
4 changes: 0 additions & 4 deletions omegaconf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ def _select_impl(
:param key:
:return:
"""
from . import ValueNode
from .omegaconf import _select_one

if key == "":
Expand All @@ -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

Expand Down
8 changes: 7 additions & 1 deletion tests/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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)
Expand Down

0 comments on commit 35ee3d7

Please sign in to comment.