-
Notifications
You must be signed in to change notification settings - Fork 112
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
Overriding configuration using an environment doesn't trigger type checks when merging into Structured config #488
Comments
Also tested on 2.0.6 |
Custom resolvers return value is not merged into the config. They can actually return anything (including incompatible objects). This behavior is intentional. |
from dataclasses import dataclass
from omegaconf import SI, OmegaConf
OmegaConf.register_resolver("foo", lambda: "not an int")
@dataclass
class Foo:
bar: int = SI("${foo:}")
foo = OmegaConf.structured(Foo)
print(foo.bar) # not an int |
Hi @omry, thanks for the explanation, that makes sense. Would you be interested in a little docs update pr, perhaps in the Interpolation subsection of the structured config section, to make this behaviour clear? Also thanks for maintaining this, its been a lovely library to use. |
Yes, a PRs to improve the docs are always welcome! Glad to hear you like OmegaConf. I also recommend that you check out Hydra, which builds on top of OmegaConf. |
This is related to omry#488
This is related to omry#488
This is related to omry#488
This is related to omry#488
This is related to omry#488
This commit fixes several issues: * For nested resolvers (ex: `${f:${g:x}}`), intermediate resolver outputs (of `g` in this example) were wrapped in a ValueNode just to be unwrapped immediately, which was wasteful. This commit pushes the node wrapping to the very last step of the interpolation resolution. * There was no type checking to make sure that the result of an interpolation had a type consistent with the node's type (when specified). Now a check is made and the interpolation result may be converted into the desired type (see omry#488). * If a resolver interpolation returns a dict / list, it is now wrapped into a DictConfig / ListConfig, instead of a ValueNode. This makes it possible to generate configs from resolvers (see omry#540) Fixes omry#488 Fixes omry#540
This commit fixes several issues: * For nested resolvers (ex: `${f:${g:x}}`), intermediate resolver outputs (of `g` in this example) were wrapped in a ValueNode just to be unwrapped immediately, which was wasteful. This commit pushes the node wrapping to the very last step of the interpolation resolution. * There was no type checking to make sure that the result of an interpolation had a type consistent with the node's type (when specified). Now a check is made and the interpolation result may be converted into the desired type (see omry#488). * If a resolver interpolation returns a dict / list, it is now wrapped into a DictConfig / ListConfig, instead of a ValueNode. This makes it possible to generate configs from resolvers (see omry#540) Fixes omry#488 Fixes omry#540
This commit fixes several issues: * For nested resolvers (ex: `${f:${g:x}}`), intermediate resolver outputs (of `g` in this example) were wrapped in a ValueNode just to be unwrapped immediately, which was wasteful. This commit pushes the node wrapping to the very last step of the interpolation resolution. * There was no type checking to make sure that the result of an interpolation had a type consistent with the node's type (when specified). Now a check is made and the interpolation result may be converted into the desired type (see omry#488). * If a resolver interpolation returns a dict / list, it is now wrapped into a DictConfig / ListConfig, instead of a ValueNode. This makes it possible to generate configs from resolvers (see omry#540) Fixes omry#488 Fixes omry#540
Validate and convert interpolation results to their intended type This PR fixes several issues: * For nested resolvers (ex: `${f:${g:x}}`), intermediate resolver outputs (of `g` in this example) were wrapped in a ValueNode just to be unwrapped immediately, which was wasteful. This commit pushes the node wrapping to the very last step of the interpolation resolution. * There was no type checking to make sure that the result of an interpolation had a type consistent with the node's type (when specified). Now a check is made and the interpolation result may be converted into the desired type (see #488). * If a resolver interpolation returns a dict / list, it is now wrapped into a DictConfig / ListConfig, instead of a ValueNode. This makes it possible to generate configs from resolvers (see #540). These configs are read-only since they are being re-generated on each access. Fixes #488 Fixes #540
Describe the bug
If I create a structured configuration with an integer field and then merge in a configuration where that fields value is taken from an environment variable, the type checks usually associated with the structured field are not triggered.
To Reproduce
Expected behavior
I expected a validation error to be raised on merge, as it would have been had I set:
override = "foo: "This is not an integer"
Additional context
The text was updated successfully, but these errors were encountered: