Skip to content

Commit

Permalink
Fixed Merging into a MISSING Structured config
Browse files Browse the repository at this point in the history
  • Loading branch information
omry committed Jun 19, 2020
1 parent 92a1d5c commit 4e97f88
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 22 deletions.
1 change: 1 addition & 0 deletions news/269.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Merging into a MISSING Structured config node expands the node first to ensure the result is legal
1 change: 1 addition & 0 deletions news/271.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix merging into a config with a read only node if merge is not mutating that node
8 changes: 3 additions & 5 deletions omegaconf/basecontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
_convert_to_omegaconf_container,
_get_value,
_is_interpolation,
_resolve_optional,
get_ref_type,
get_value_kind,
get_yaml_loader,
is_dict_annotation,
is_primitive_container,
is_primitive_dict,
is_structured_config,
get_ref_type,
is_dict_annotation,
_resolve_optional,
)
from .base import Container, ContainerMetadata, Node
from .errors import MissingMandatoryValue, ReadonlyConfigError, ValidationError
Expand Down Expand Up @@ -232,8 +232,6 @@ def pretty(self, resolve: bool = False, sort_keys: bool = False) -> str:
@staticmethod
def _map_merge(dest: "BaseContainer", src: "BaseContainer") -> None:
"""merge src into dest and return a new copy, does not modified input"""
from omegaconf import OmegaConf

from .dictconfig import DictConfig
from .listconfig import ListConfig
from .nodes import ValueNode
Expand Down
19 changes: 2 additions & 17 deletions tests/test_merge.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Any, Tuple
from dataclasses import dataclass
from typing import Any, Tuple

import pytest

from omegaconf import (
Expand Down Expand Up @@ -217,22 +218,6 @@ def test_merge(inputs: Any, expected: Any) -> None:
OmegaConf.merge(*configs)


"""
from omegaconf import OmegaConf, MISSING
from dataclasses import dataclass
@dataclass
class A:
a : int = 10
@dataclass
class B:
x : A = MISSING
OmegaConf.merge(B, {"x": {}})
"""


def test_merge_error_retains_type() -> None:
cfg = OmegaConf.structured(ConcretePlugin)
with pytest.raises(ValidationError):
Expand Down

0 comments on commit 4e97f88

Please sign in to comment.