-
Notifications
You must be signed in to change notification settings - Fork 108
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
get_attr_data
doesn't handle default factory correctly
#945
Comments
Thanks for the bug report! |
In a sense this is due to that OmegaConf infers types from values rather than type annotations. I wonder if there can be a way to use type annotations instead (which would also address the structure configs inheritance issue described in facebookresearch/hydra#2227 ) |
I ran into this bug as well just now. However, I have found it does work correctly with the stdlib dataclasses. This can serve as a possible workaround for others who run into this, and may aid in tracking down the source of the problem. For reference, here's a minimalistic dataclasses example that works correctly for which the equivalent attrs version throws the exception described in the original report: from dataclasses import dataclass, field
@dataclass
class Config:
a_list_of_strings: list[str] = field(default_factory=list) |
If we merge a
MISSING
field, with anattrs
class structured config that uses default factory (e.g., for specifying defaults list in hydra), thisexpand
callomegaconf/omegaconf/basecontainer.py
Lines 327 to 342 in 6a4fd51
will call
node._set_value(attrs_class)
, which callsget_attr_data(attrs_class)
.omegaconf/omegaconf/_utils.py
Lines 313 to 334 in 6a4fd51
and since it is given a class, it will use
attrs.Attribute
'sattribute.default
value as the values to set attributes. This normally works, but however, if the attribute uses default factory, theattribute.default
is anattrs.Factory
object! Then OmegaConf errors out.To Reproduce
[skipping long stack frames]
The text was updated successfully, but these errors were encountered: