You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure if it’s a bug or just not supported, I cannot opine for sure from the docs, feel free to clarify. I have noticed that the validation on structured configs does not go deeper than one level when using a nested dataclass.
fromdataclassesimportdataclass, fieldfromomegaconfimportOmegaConf@dataclassclassDeeplyNestedConf:
an_int: int=10a_string: str="test"@dataclassclassStructuredConf:
single_nest: dict[str, DeeplyNestedConf] =field(default_factory=dict)
double_nest: dict[str, dict[str, DeeplyNestedConf]] =field(default_factory=dict)
deftest_nested_struct():
yaml=""" single_nest: level_1: an_int: 20 double_nest: level_1: nested_level_1: an_int: 30 a_string: this is not typed nested_level_2: an_int: 40 a_typo: this does not fail """schema=OmegaConf.structured(StructuredConf())
untyped=OmegaConf.create(yaml)
typed=OmegaConf.merge(schema, untyped)
structured_conf=OmegaConf.to_object(typed) # type: StructuredConfassertisinstance(structured_conf.single_nest["level_1"], DeeplyNestedConf) # Awesome!not_typed=structured_conf.double_nest["level_1"]["nested_level_1"]
assertnotisinstance(not_typed, DeeplyNestedConf) # why not?assertisinstance(not_typed, dict) # it’s just a dict :-(did_not_fail_validation=structured_conf.double_nest["level_1"]["nested_level_2"]
assertnotisinstance(did_not_fail_validation, DeeplyNestedConf)
assertisinstance(did_not_fail_validation, dict)
While the first level of nesting works great, I was expecting the merge to fail because of the object named did_not_fail_validation. And even if the wrong yaml was fixed, I would have expected the not_typed object to be a DeeplyNestedConf.
Looking forward to knowing your thoughts.
Additional context
OmegaConf version: 2.2.3
Python version: 3.10.6
Operating system: win-64
Please provide a minimal repro
The text was updated successfully, but these errors were encountered:
We'd want to (1) add tests based on the OP's example and (2) add tests to make sure that the _metadata field on the newly created DictConfig / ListConfig object are initialized correctly. My hunch is that, as the patch stands, the key_type and element_type on DictConfig and ListConfig are not set properly.
The "wrong error message" you mentioned might not be a big deal.
Hi folks,
Not sure if it’s a bug or just not supported, I cannot opine for sure from the docs, feel free to clarify. I have noticed that the validation on structured configs does not go deeper than one level when using a nested dataclass.
While the first level of nesting works great, I was expecting the merge to fail because of the object named
did_not_fail_validation
. And even if the wrong yaml was fixed, I would have expected thenot_typed
object to be aDeeplyNestedConf
.Looking forward to knowing your thoughts.
Additional context
The text was updated successfully, but these errors were encountered: