Skip to content
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

Structured Config created from dataclass instance with default_factory does not retain user-assigned MISSING field. #831

Closed
Jasha10 opened this issue Dec 2, 2021 · 0 comments · Fixed by #832
Assignees
Labels
bug Something isn't working priority_medium
Milestone

Comments

@Jasha10
Copy link
Collaborator

Jasha10 commented Dec 2, 2021

Closely related to #830.

Describe the bug
Given a dataclass instance obj, the DictConfig object OmegaConf.structured(obj) created from obj should have fields that correspond to the fields of the original object obj.

Currently the above fails if obj has a field with a default_factory and with a user-assigned MISSING value, e.g. if the user creates obj like this:

obj = MyConf(fieldname=MISSING)

where MyConf.fieldname has a non-missing default_factory.

To Reproduce

from dataclasses import dataclass, field
from typing import List

from omegaconf import MISSING, OmegaConf


@dataclass
class ConfigWithLeaf:
    leaf: int = 1


input1 = ConfigWithLeaf(leaf=MISSING)
assert input1.leaf == MISSING                  # ok
conf1 = OmegaConf.structured(input1)
assert OmegaConf.is_missing(conf1, "leaf")     # ok


@dataclass
class ConfigWithList:
    lst: List[int] = field(default_factory=lambda: [1, 2, 3])


input2 = ConfigWithList(lst=MISSING)
assert input2.lst == MISSING                   # ok
conf2 = OmegaConf.structured(input2)
assert OmegaConf.is_missing(conf2, "lst")      # AssertionError

Expected behavior
All four assertions above should pass.

Additional context

  • OmegaConf version: master branch
@Jasha10 Jasha10 added the bug Something isn't working label Dec 2, 2021
Jasha10 added a commit to Jasha10/omegaconf that referenced this issue Dec 2, 2021
Jasha10 added a commit to Jasha10/omegaconf that referenced this issue Dec 2, 2021
@Jasha10 Jasha10 added this to the OmegaConf 2.2 milestone Feb 15, 2022
@Jasha10 Jasha10 self-assigned this Feb 15, 2022
@Jasha10 Jasha10 removed their assignment Apr 7, 2022
Jasha10 added a commit to Jasha10/omegaconf that referenced this issue Apr 13, 2022
Jasha10 added a commit to Jasha10/omegaconf that referenced this issue Apr 13, 2022
@Jasha10 Jasha10 self-assigned this Apr 13, 2022
@Jasha10 Jasha10 linked a pull request Apr 13, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority_medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants