diff --git a/omegaconf/resolvers/oc/__init__.py b/omegaconf/resolvers/oc/__init__.py index ac8fb8e0f..a05c72463 100644 --- a/omegaconf/resolvers/oc/__init__.py +++ b/omegaconf/resolvers/oc/__init__.py @@ -13,11 +13,7 @@ def create(obj: Any, _parent_: Container) -> Any: from omegaconf import OmegaConf assert isinstance(_parent_, BaseContainer) - ret = OmegaConf.create(obj, parent=_parent_) - # Since this node is re-generated on-the-fly, changes would be lost: we mark it - # as read-only to avoid mistakes. - ret._set_flag("readonly", True) - return ret + return OmegaConf.create(obj, parent=_parent_) def env(key: str, default: Any = _DEFAULT_MARKER_) -> Optional[str]: diff --git a/tests/interpolation/built_in_resolvers/test_create_resolver.py b/tests/interpolation/built_in_resolvers/test_create_resolver.py index 6d2b8334f..c9c239b9f 100644 --- a/tests/interpolation/built_in_resolvers/test_create_resolver.py +++ b/tests/interpolation/built_in_resolvers/test_create_resolver.py @@ -2,7 +2,7 @@ from pytest import mark, param, raises -from omegaconf import DictConfig, ListConfig, OmegaConf, flag_override +from omegaconf import DictConfig, ListConfig, OmegaConf from omegaconf.errors import InterpolationResolutionError @@ -54,7 +54,7 @@ def test_create(cfg: Any, key: str, expected: Any) -> None: val = cfg[key] assert val == expected assert type(val) is type(expected) - assert val._get_flag("readonly") + assert val._get_flag("readonly") is None def test_create_error() -> None: @@ -74,14 +74,13 @@ def test_write_into_output() -> None: } ) x = cfg.x - assert x._get_flag("readonly") + assert x._get_flag("readonly") is None - # "Force-write" into the node generated by `oc.create`. - with flag_override(x, "readonly", False): - x.a = 1 - x.b.c = 2 + # Write into the node generated by `oc.create`. + x.a = 1 + x.b.c = 2 - # The node that we force-wrote into should be modified. + # The node that we wrote into should be modified. assert x.a == 1 assert x.b.c == 2 @@ -132,3 +131,9 @@ def test_resolver_output_list_to_listconfig( assert isinstance(c.x, ListConfig) assert c.x == expected assert c.x._parent is c + + +def test_merge_into_created_node() -> None: + cfg: Any = OmegaConf.create({"x": "${oc.create:{y: 0}}"}) + cfg = OmegaConf.merge(cfg, {"x": {"z": 1}}) + assert cfg == {"x": {"y": 0, "z": 1}}