Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly crash when trying to access child of a value node #366

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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