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

OmegaConf.structured(...) may mutate its input #908

Open
Jasha10 opened this issue May 2, 2022 · 0 comments · Fixed by #909
Open

OmegaConf.structured(...) may mutate its input #908

Jasha10 opened this issue May 2, 2022 · 0 comments · Fixed by #909
Labels
bug Something isn't working
Milestone

Comments

@Jasha10
Copy link
Collaborator

Jasha10 commented May 2, 2022

Describe the bug
OmegaConf.structured(...) mutates its input when called on a dataclass or dataclass instance that has a structured DictConfig instance as one of its fields.

To Reproduce

from dataclasses import dataclass
from omegaconf import OmegaConf

@dataclass
class User:
    name: str = "Bond"
    age: int = 7

@dataclass
class HasUser:
    user: User

has_user1 = OmegaConf.structured(HasUser(User()))
assert has_user1.user._parent is has_user1
has_user2 = OmegaConf.structured(HasUser(has_user1.user))
assert has_user2.user._parent is has_user2
assert has_user1.user._parent is None  # has_user1.user has been mutated
assert has_user1.user is not has_user2.user

Expected behavior
The creation of has_user2 should not mutate has_user1.user.
Most OmegaConf creation and assignment methods do not mutate their inputs.

Additional context

  • OmegaConf version: latest dev version (main branch)
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.

2 participants