Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix handling of throw_on_missing flag for select() on ListConfig #564

Merged
merged 4 commits into from
Feb 24, 2021

Conversation

odelalleau
Copy link
Collaborator

Fixes #563

news/563.bugfix Outdated
@@ -0,0 +1 @@
Selecting a missing node from a ListConfig with `throw_on_missing` set to True now raises the intended exception.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function name here to be more specific about what you mean by "selecting"

Suggested change
Selecting a missing node from a ListConfig with `throw_on_missing` set to True now raises the intended exception.
OmegaConf.select() a missing node from a ListConfig with `throw_on_missing` set to True now raises the intended exception.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in b9a5db6

@@ -85,7 +86,7 @@ def test_select_default(
pytest.param({"missing": "???"}, "missing", id="missing"),
],
)
def test_select_default_throw_on_missing(
def test_select_default_throw_on_missing_dict(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old function name seems better. why rename it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before there was just the test_select_default_throw_on_missing function;
now there is a test_select_default_throw_on_missing_dict function and a test_select_default_throw_on_missing_list function.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is testing both dicts and lists.

Copy link
Collaborator Author

@odelalleau odelalleau Feb 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was only testing a dict here, but actually you're right that I can re-use the same test for lists as well (somehow I thought that set_struct was only for DictConfig, but looks like I was wrong).

I changed it in cef0a23 585183c

Comment on lines 103 to 119
@pytest.mark.parametrize(
"cfg, key",
[
pytest.param(["???"], "0", id="missing"),
],
)
def test_select_default_throw_on_missing_list(
cfg: Any,
key: Any,
) -> None:
cfg = OmegaConf.create(cfg)

# throw on missing still throws if default is provided
with pytest.raises(MissingMandatoryValue):
OmegaConf.select(cfg, key, default=0, throw_on_missing=True)


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this is covered by the first test you changed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this test covers the throw_on_missing=True case, the other one does not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the list:missing test I added is a success case when throw_on_missing is False (it was working before as well, but it wasn't tested, I just added it for better test coverage)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it a success case if the test body has this?

with pytest.raises(MissingMandatoryValue):
   ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to clear up the confusion:

  • I thought by "first test you changed" you meant test_select(): I indeed added a new test here (id list:missing) to test the case where we select a missing value with throw_on_missing set to False (which worked before, and still works here)
  • The test with with pytest.raises(MissingMandatoryValue): is test_select_default_throw_on_missing: this tests the case where throw_on_missing is True. The new test I added here would have failed before this PR.

Copy link
Collaborator

@Jasha10 Jasha10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@@ -85,7 +86,7 @@ def test_select_default(
pytest.param({"missing": "???"}, "missing", id="missing"),
],
)
def test_select_default_throw_on_missing(
def test_select_default_throw_on_missing_dict(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is testing both dicts and lists.

Comment on lines 103 to 119
@pytest.mark.parametrize(
"cfg, key",
[
pytest.param(["???"], "0", id="missing"),
],
)
def test_select_default_throw_on_missing_list(
cfg: Any,
key: Any,
) -> None:
cfg = OmegaConf.create(cfg)

# throw on missing still throws if default is provided
with pytest.raises(MissingMandatoryValue):
OmegaConf.select(cfg, key, default=0, throw_on_missing=True)


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it a success case if the test body has this?

with pytest.raises(MissingMandatoryValue):
   ...

@odelalleau odelalleau force-pushed the list_select_throw_missing branch from cef0a23 to 585183c Compare February 24, 2021 22:21
Copy link
Owner

@omry omry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good.
I think GitHub diff view played some tricks on all of us here.

@omry omry merged commit 01c530d into omry:master Feb 24, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

select() ignores throw_on_missing for ListConfig
3 participants