omry / omegaconf

Flexible Python configuration system. The last one you will ever need.
BSD 3-Clause "New" or "Revised" License
1.91k stars 104 forks source link

Default Not Being Set #1110

Closed timolson closed 1 year ago

timolson commented 1 year ago

First, I love OmegaConf so far. It's almost perfect...

Describe the bug My config has a nested dict[...,list[Child]] structure, where nested elements have defaults, but the defaults are NOT being set.

To Reproduce

from dataclasses import dataclass
from omegaconf import OmegaConf

@dataclass
class ParentConfig:
    children: dict[str, list['ChildConfig']]

@dataclass
class ChildConfig:
    required: int
    optional: int = 3

schema = OmegaConf.structured(ParentConfig)
conf = OmegaConf.create({'children': {'items': [{'required': 'r'}]}}) # NOTE: wrong type for 'required'
print(OmegaConf.merge(schema, conf)

Outputs: {'children': {'items': [{'required': 'r'}]}}

Expected behavior The ChildConfig item should have optional=3

Notice that I used the wrong type for required, passing a string instead of an int. This suggests that the typing system is not recursing properly. Perhaps only one level of nesting is hardcoded?

Additional context

odelalleau commented 1 year ago

Thanks, at first sight it looks this may be related to #1058

timolson commented 1 year ago

Yes, agreed, it's likely the same issue.

If I remove the list and just have a dict of objects, it works.

omry commented 1 year ago

Thanks for the report. Closing as a duplicate.