-
Notifications
You must be signed in to change notification settings - Fork 122
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
Conversation
There was a problem hiding this 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")
.
Rebased onto master. |
|
This is what I had in mind, yes. I added it in #513. |
👉 View analysis in DeepCode’s Dashboard | Configure the bot |
There was a problem hiding this 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)
Rebased onto |
There was a problem hiding this 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).
That works!
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much cleaner.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why is _dereference_node throwing a MandatoryMissingValue is throw_on_missing is False?
- Why are you passing False to throw_on_missing and not the input flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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.
Marking this PR as needing possible API redesign after #502 gets merged. |
This PR is old; closing in favor of #730. |
Closes #501