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.update AssertionError on key pointing into None-valued DictConfig. #1035

Open
4 tasks done
Jasha10 opened this issue Nov 17, 2022 · 2 comments
Open
4 tasks done

Comments

@Jasha10
Copy link
Collaborator

Jasha10 commented Nov 17, 2022

Describe the bug
The OmegaConf.update method throws an AssertionError when the key argument passed to OmegaConf.update points inside of a DictConfig instance whose _content is None.

To Reproduce

from dataclasses import dataclass
from typing import Optional
from omegaconf import OmegaConf
from pytest import raises

@dataclass
class Child:
    x: int = 123
    y: int = 456

@dataclass
class Parent:
    child: Optional[Child] = None

cfg = OmegaConf.structured(Parent)

with raises(AssertionError, match="Unexpected type for root: NoneType"):
    OmegaConf.update(cfg=cfg, key="child.x", value=789)

Expected behavior
I think OmegaConf should fail gracefully (or maybe not fail at all) in this situation rather than throwing an AssertionError.

Additional context

  • OmegaConf version: 2.2.3
  • Python version: 3.9.12
  • Operating system: ubuntu 20.04
  • Please provide a minimal repro

Edit:

Here is the full traceback:
$ OC_CAUSE=1 python repro2.py
Traceback (most recent call last):
  File "/home/homestar/dev/mrepo/pysc/repro2.py", line 17, in <module>
    OmegaConf.update(cfg=cfg, key="child.x", value=789)
  File "/home/homestar/miniconda3/envs/pysc/lib/python3.10/site-packages/omegaconf/omegaconf.py", line 709, in update
    assert isinstance(
AssertionError: Unexpected type for root: NoneType
@Jasha10 Jasha10 added this to the OmegaConf 2.2.3 milestone Nov 18, 2022
@Jasha10
Copy link
Collaborator Author

Jasha10 commented Nov 18, 2022

OmegaConf.merge does not exhibit the same failure mode.

-- Click here for an example --
from dataclasses import dataclass
from typing import Optional
from omegaconf import OmegaConf

@dataclass
class Child:
    x: int = 123
    y: int = 456

@dataclass
class Parent:
    child: Optional[Child] = None

cfg = OmegaConf.structured(Parent)
other = {"child": {"x": 789}}
out = OmegaConf.merge(cfg, other)

assert OmegaConf.get_type(out.child) is Child
assert out == {"child": {"x": 789, "y": 456}}

I feel that OmegaConf.update's behavior should be consistent with that of OmegaConf.merge: calling update should result in a node out.child that is a non-None structured config backed the Child class.

@omry
Copy link
Owner

omry commented Jan 19, 2023

I feel that OmegaConf.update's behavior should be consistent with that of OmegaConf.merge: calling update should result in a node out.child that is a non-None structured config backed the Child class.

Dunno, that would be an insert, not an update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants