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 subclass of dataclass does not have correct initial values #817

Closed
Jasha10 opened this issue Nov 8, 2021 · 0 comments · Fixed by #826
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@Jasha10
Copy link
Collaborator

Jasha10 commented Nov 8, 2021

Describe the bug
When an omegaconf structured config is created from a subclass of a dataclass, the config is not initialized with the default values from the subclass; instead the default values from the superclass are used.

To Reproduce

from dataclasses import dataclass, field
from typing import Any, Dict, List

from omegaconf import MISSING, OmegaConf


@dataclass
class ParentConfig:
    model_depth: int = MISSING
    model_list: List[int] = field(default_factory=lambda: [5, 6])
    model_list_2: List[int] = MISSING
    model_dict: Dict[str, Any] = MISSING


@dataclass
class ChildConfig(ParentConfig):
    model_depth: int = 5
    model_list_2: List[int] = field(default_factory=lambda: [1, 2, 3])
    model_dict: Dict[str, Any] = field(default_factory=lambda: {"a": 5, "b": 6})


cfg = OmegaConf.structured(ChildConfig)
print(OmegaConf.to_yaml(cfg))
# Actual Output:

model_depth: 5
model_list:
- 5
- 6
model_list_2: ???
model_dict: ???

# Expected Output:

model_depth: 5
model_list:
- 5
- 6
model_list_2:
- 1
- 2
- 3
model_dict:
  a: 5
  b: 6

This is a dataclass issue; when using attr classes instead of dataclasses, there is no bug.

Additional context

@Jasha10 Jasha10 added the bug Something isn't working label Nov 8, 2021
@Jasha10 Jasha10 self-assigned this Nov 11, 2021
@Jasha10 Jasha10 added this to the OmegaConf 2.2 milestone Nov 11, 2021
Jasha10 added a commit to Jasha10/omegaconf that referenced this issue Nov 22, 2021
As of this commit, the following two tests are failing:
```
pytest tests/structured_conf/test_structured_config.py -k 'dataclasses-dict_overwrite_missing'
pytest tests/structured_conf/test_structured_config.py -k 'dataclasses-list1_overwrite_missing'
```
Jasha10 added a commit to Jasha10/omegaconf that referenced this issue Apr 12, 2022
Jasha10 added a commit that referenced this issue Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant