-
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
Better and more consistent handling of the "missing" status #543
Comments
The only surprise to me is This behavior is driving the contains API behavior for missing fields:
which returns False. I am open to changing this behavior but we should consider it carefully and check in downstream apps (at least in Hydra). |
Yes, that was in #462, and I think it makes sense to also extend the same logic (not being missing) to any interpolation using a missing field, not just string interpolations, including in particular:
The last one is probably the most controversial, but I think it is what makes most sense to have simple and consistent semantics for what "missing" means ("has the key been set in the config?"). I ran Hydra's test suite with this change btw, and nothing broke. |
The origin of this behavior predated the OmegaConf.is_missing() public API. Now that we have a formal API to check if a field is missing I support this change. |
* Interpolations are never considered to be missing anymore, even if they point to a missing node * When resolving an expression containing an interpolation pointing to a missing node, if `throw_on_missing` is False, then the result is always `None` (while it used to either be a missing Node, or an expression computed from the "???" string) * Similarly, this commit also ensures that if `throw_on_resolution_failure` is False, then resolving an interpolation resulting in a resolution failure always leads to the result being `None` (instead of potentially being an expression computed from `None`) Fixes omry#543
* Interpolations are never considered to be missing anymore, even if they point to a missing node * When resolving an expression containing an interpolation pointing to a missing node, if `throw_on_missing` is False, then the result is always `None` (while it used to either be a missing Node, or an expression computed from the "???" string) * Similarly, this commit also ensures that if `throw_on_resolution_failure` is False, then resolving an interpolation resulting in a resolution failure always leads to the result being `None` (instead of potentially being an expression computed from `None`) Fixes omry#543
* Interpolations are never considered to be missing anymore, even if they point to a missing node * When resolving an expression containing an interpolation pointing to a missing node, if `throw_on_missing` is False, then the result is always `None` (while it used to either be a missing Node, or an expression computed from the "???" string) * Similarly, this commit also ensures that if `throw_on_resolution_failure` is False, then resolving an interpolation resulting in a resolution failure always leads to the result being `None` (instead of potentially being an expression computed from `None`) Fixes omry#543
* Interpolations are never considered to be missing anymore, even if they point to a missing node * When resolving an expression containing an interpolation pointing to a missing node, if `throw_on_missing` is False, then the result is always `None` (while it used to either be a missing Node, or an expression computed from the "???" string) * Similarly, this commit also ensures that if `throw_on_resolution_failure` is False, then resolving an interpolation resulting in a resolution failure always leads to the result being `None` (instead of potentially being an expression computed from `None`) Fixes omry#543
* Interpolations are never considered to be missing anymore, even if they point to a missing node * When resolving an expression containing an interpolation pointing to a missing node, if `throw_on_missing` is False, then the result is always `None` (while it used to either be a missing Node, or an expression computed from the "???" string) * Similarly, this commit also ensures that if `throw_on_resolution_failure` is False, then resolving an interpolation resulting in a resolution failure always leads to the result being `None` (instead of potentially being an expression computed from `None`) Fixes omry#543
* Interpolations are never considered to be missing anymore, even if they point to a missing node * When resolving an expression containing an interpolation pointing to a missing node, if `throw_on_missing` is False, then the result is always `None` (while it used to either be a missing Node, or an expression computed from the "???" string) * Similarly, this commit also ensures that if `throw_on_resolution_failure` is False, then resolving an interpolation resulting in a resolution failure always leads to the result being `None` (instead of potentially being an expression computed from `None`) Fixes omry#543
* Interpolations are never considered to be missing anymore, even if they point to a missing node * When resolving an expression containing an interpolation pointing to a missing node, an `InterpolationToMissingValueError` exception is raised * When resolving an expression containing an interpolation pointing to a node that does not exist, an `InterpolationKeyError` exception is raised * `key in cfg` returns True whenever `key` is an interpolation, even if it cannot be resolved (including interpolations to missing nodes) * `get()` and `pop()` no longer return the default value in case of interpolation resolution failure (same thing for `OmegaConf.select()`) * If `throw_on_resolution_failure` is False, then resolving an interpolation resulting in a resolution failure always leads to the result being `None` (instead of potentially being an expression computed from `None`) Fixes #543 Fixes #561 Fixes #562 Fixes #565
* Interpolations are never considered to be missing anymore, even if they point to a missing node * When resolving an expression containing an interpolation pointing to a missing node, an `InterpolationToMissingValueError` exception is raised * When resolving an expression containing an interpolation pointing to a node that does not exist, an `InterpolationKeyError` exception is raised * `key in cfg` returns True whenever `key` is an interpolation, even if it cannot be resolved (including interpolations to missing nodes) * `get()` and `pop()` no longer return the default value in case of interpolation resolution failure (same thing for `OmegaConf.select()`) * If `throw_on_resolution_failure` is False, then resolving an interpolation resulting in a resolution failure always leads to the result being `None` (instead of potentially being an expression computed from `None`) Fixes omry#543 Fixes omry#561 Fixes omry#562 Fixes omry#565
Describe the bug
Currently the handling of a missing node in interpolations can lead to surprising behavior like:
which prints:
The two potentially surprising things are:
x
is considered as missing whiley
isn't (while both refer to a missing node)y
is happily dereferenced into aStringNode
containing the string"abc ???"
Expected behavior
I propose the following behavior:
None
(unlessthrow_on_missing
throw_on_resolution_failure
is True, in which case it should raise theInterpolationToMissingValueError
exception)(Edit: I replaced
throw_on_missing
withthrow_on_resolution_failure
in point 2 becausethrow_on_missing
when dereferencing a node should only refer to the status of the node being referenced, not to what happens when trying to resolve interpolations, whilethrow_on_resolution_failure
relates to errors encountered when resolving interpolations)The text was updated successfully, but these errors were encountered: