Calling `OmegaConf.to_container` on interpolation-to-missing errors
See original GitHub issueThe behavior of the OmegaConf.to_container
method has changed with respect to interpolation-to-missing nodes.
With OmegaConf v2.0.6, no exception is raised on encountering interpolation-to-missing:
>>> cfg = OmegaConf.create({"missing": "???", "x": "${missing}"})
>>> OmegaConf.to_container(cfg, resolve=True)
{'missing': '???', 'x': '???'}
Currently on the master
branch, this no longer works: an InterpolationToMissingValueError
is raised.
This behavior change resulted from #545.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
throw_on_missing keyword argument for OmegaConf ... - GitHub
Feature: Currently, calling OmegaConf.to_container(cfg) can result in a python ... Calling OmegaConf.to_container on interpolation-to-missing errors #727.
Read more >Installation — OmegaConf 2.1.3.dev0 documentation
Add new interpolation types by registering resolvers using OmegaConf.register_new_resolver() . Such resolvers are called when the config node is accessed.
Read more >OmegaConf Documentation
INSTANTIATE, interpolations nested within a structured config node will be resolved, even if OmegaConf. to_container is called with the the keyword argument ...
Read more >Installation — OmegaConf 2.0.6 documentation - Read the Docs
You can create OmegaConf objects from multiple sources. ... "oops" cannot be converted to an int Traceback (most recent call last): ... omegaconf.errors....
Read more >OmegaConf Documentation
OmegaConf is a YAML based hierarchical configuration system, with support for merging configurations from multi- ple sources (files, CLI ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I actually disagree with
to_container(..., resolve=True, throw_on_missing=False)
allowing interpolations to missing values. The main reason is that this would be inconsistent with (at least)OmegaConf.select()
wherethrow_on_missing=False
doesn’t allow this, and instead one should usethrow_on_resolution_failure=False
(resulting in a value ofNone
).This is because trying to resolve an interpolation to a missing value is now considered an error (instead of being considered as yielding a missing value). This is indeed a breaking change, and it should have probably been mentioned in another news item attached to #545 (@omry should I submit a PR for this?)
I would suggest not to try and support the example given at the top unless there is a good reason for it. And if we do want to support it, I think it shouldn’t be with
throw_on_missing=False
. This may actually require revisiting some key decisions made in #545 so it should be considered carefully.This is a collateral damage from a breaking change. Not really a bug, more like something we failed to mention as a breaking change (we can add a news fragment for it now).
When introducing throw_on_missing, I agree that having it set to False should suppress the InterpolationToMissingValueError as well.