Open edlanglois opened 1 year ago
Thanks for the report, @edlanglois.
It is indeed inconsistent that merge(base, no_nested_list)
works and merge(base, nested_list)
gets rejected. What you've put your finger on is that merge semantics for nested containers do not perform type coercion aggressively.
>>> @dataclass
... class Nested:
... l: list[list[str]]
...
>>> OmegaConf.merge(Nested, {"l": [[2]]}) # rejects `2` as not a string
Traceback ...
>>> @dataclass
... class Shallow:
... l: list[str]
...
>>> OmegaConf.merge(Shallow, {"l": [2]}) # coerces `2` to a string
{'l': ['2']}
Motivation for this design decision was that aggressive coercion might be unwanted (i.e. a ValidationError
might be more desirable if the data are mistyped).
Your writeup also highlights the case of coercion from str
to Enum
. It might make sense to add a special case handling for str -> Enum
coercion in nested containers since .yaml
files don't support enum values natively. @omry, what do you think?
Thanks for explaining the underlying cause. Yes, my issue is that I'm unable to merge a .yaml config into the nested structured config.
Your writeup also highlights the case of coercion from
str
toEnum
. It might make sense to add a special case handling forstr -> Enum
coercion in nested containers since.yaml
files don't support enum values natively. @omry, what do you think?
I am open to a fix in that direction. Ideally it would not be handled as a special condition though.
Ideally it would not be handled as a special condition though.
What do you have in mind? Enabling type coercion fully within nested containers?
I think so.
Describe the bug When merging into a structured config with a field of type
List[List[SomeEnum]]
, any enums in the second (non-structured) config fail validation withThis does not occur for direct use of enums (
value: SomeEnum
) or non-nested lists (value: List[SomeEnum]
).To Reproduce
Expected behavior I expect the merge of
base
andnested_list
to complete successfully, resulting in the following structure:instead I get
Additional context