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

To container throw on missing #503

Closed
wants to merge 7 commits into from
Closed

To container throw on missing #503

wants to merge 7 commits into from

Conversation

Jasha10
Copy link
Collaborator

@Jasha10 Jasha10 commented Jan 30, 2021

Closes #501

@Jasha10 Jasha10 marked this pull request as draft January 30, 2021 23:02
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.

It will probably be simpler to
node = conf._get_node(key, throw_on_missing=True)

Try to line the error message with the normal error for missing values (raise MissingMandatoryValue("Missing mandatory value: $FULL_KEY").

@Jasha10
Copy link
Collaborator Author

Jasha10 commented Feb 3, 2021

Rebased onto master.

@Jasha10
Copy link
Collaborator Author

Jasha10 commented Feb 3, 2021

It will probably be simpler to
node = conf._get_node(key, throw_on_missing=True)

conf._get_node does not have a throw_on_missing keyword option.
Do you mean that I should add a throw_on_missing keyword argument to the _get_node signature?

@omry
Copy link
Owner

omry commented Feb 3, 2021

Do you mean that I should add a throw_on_missing keyword argument to the _get_node signature?

This is what I had in mind, yes. I added it in #513.

@ghost
Copy link

ghost commented Feb 4, 2021

Congratulations 🎉. DeepCode analyzed your code in 2.618 seconds and we found no issues. Enjoy a moment of no bugs ☀️.

👉 View analysis in DeepCode’s Dashboard | Configure the bot

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.

Marking as request-changes (see prev comments)

@Jasha10
Copy link
Collaborator Author

Jasha10 commented Feb 11, 2021

Rebased onto master

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.

Can't comment on code you didn't change but I found what I was thinking about with the _get_node() comment:

            retdict: Dict[str, Any] = {}
            for key in conf.keys():
                node = conf._get_node(key)

In above _get_node(), what happens if you use conf._get_node(key, throw_on_missing=throw_on_missing)?

(You will probably need to do the same for ListConfig somwehere).

@Jasha10
Copy link
Collaborator Author

Jasha10 commented Feb 12, 2021

In above _get_node(), what happens if you use conf._get_node(key, throw_on_missing=throw_on_missing)?

That works!
There are a few test failures in test_errors.py which look like this:

AssertionError: Regex pattern 'Missing mandatory value: subcfg.x' does not match 'Missing mandatory value'.

If it's ok with you to change the error message, I'll make the change to using conf._get_node(key, throw_on_missing_value=throw_on_missing) and will update the test_errors.py error messages.

Edit: nevermind, all of the assertion errors were for test cases that are introduced by this PR; changing the error messages will not break anything. I'll make the change to using conf._get_node(key, throw_on_missing_value=throw_on_missing)

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.

much cleaner.

@Jasha10 Jasha10 marked this pull request as ready for review February 12, 2021 23:27
@Jasha10
Copy link
Collaborator Author

Jasha10 commented Feb 18, 2021

Currently code coverage tests are failing because the except blocks from the latest commit fe32082 have no coverage. Those try/except statements were added in anticipation of #545, and the coverage issue should be resolved once this branch is rebased onto that one.

Comment on lines +232 to +238
try:
node = node._dereference_node(
throw_on_missing=False, throw_on_resolution_failure=True
)
except MissingMandatoryValue as e:
assert node is not None
conf._format_and_raise(key=key, value=node._value(), cause=e)
Copy link
Owner

Choose a reason for hiding this comment

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

  1. Why is _dereference_node throwing a MandatoryMissingValue is throw_on_missing is False?
  2. Why are you passing False to throw_on_missing and not the input flag?

Copy link
Collaborator Author

@Jasha10 Jasha10 Feb 18, 2021

Choose a reason for hiding this comment

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

  1. Why is _dereference_node throwing a MandatoryMissingValue is throw_on_missing is False?

This is because we are calling _dereference_node with throw_on_resolution_failure=True.

Edit:
I was mistaken about what the throw_on_resolution_failure flag is doing.
I think I need to investigate this a bit more...

If #545 is merged in it's current state, _dereference_node will raise MandatoryMissingValue if throw_on_resolution_failure==True and the interpolation cannot be resolved.

This being said, I actually think it makes more sense to change this from

_dereference_node(..., throw_on_resolution_failure=True)

to

_dereference_node(..., throw_on_resolution_failure=throw_on_missing)

so that resolution failure will not cause error if the user does not specify the throw_on_missing option. I'll add tests to this effect...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. Why are you passing False to throw_on_missing and not the input flag?

The current workflow is:

  • first, get the node and (optionally) throw if missing:
node = conf._get_node(key, throw_on_missing_value=throw_on_missing)
  • second: if resolve==True, dereference the node:
node = node._dereference_node(throw_on_missing=False, throw_on_resolution_failure=True)

Since the _get_node call already has throw_on_missing_value=throw_on_missing, it would be redundant to use the throw_on_missing flag in the _dereference_node call as well.

@Jasha10 Jasha10 marked this pull request as draft February 18, 2021 21:40
@Jasha10
Copy link
Collaborator Author

Jasha10 commented Feb 18, 2021

#545 will change the behavior of _dereference_node significantly enough that it makes sense to put this PR on hold until #545 gets merged.

@Jasha10
Copy link
Collaborator Author

Jasha10 commented Mar 15, 2021

Marking this PR as needing possible API redesign after #502 gets merged.

@Jasha10
Copy link
Collaborator Author

Jasha10 commented May 21, 2021

This PR is old; closing in favor of #730.

@Jasha10 Jasha10 closed this May 21, 2021
@Jasha10 Jasha10 deleted the to-container-throw-on-missing branch June 4, 2021 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: throw_on_missing keyword argument for OmegaConf.to_container
2 participants