diff --git a/omegaconf/_utils.py b/omegaconf/_utils.py index ffec246a3..978bfae99 100644 --- a/omegaconf/_utils.py +++ b/omegaconf/_utils.py @@ -137,6 +137,7 @@ def get_yaml_loader() -> Any: class OmegaConfLoader(yaml.SafeLoader): # type: ignore def construct_mapping(self, node: yaml.Node, deep: bool = False) -> Any: keys = set() + constructor = super().construct_mapping(node, deep=deep) for key_node, value_node in node.value: if key_node.tag != yaml.resolver.BaseResolver.DEFAULT_SCALAR_TAG: continue @@ -148,7 +149,7 @@ def construct_mapping(self, node: yaml.Node, deep: bool = False) -> Any: key_node.start_mark, ) keys.add(key_node.value) - return super().construct_mapping(node, deep=deep) + return constructor loader = OmegaConfLoader loader.add_implicit_resolver( diff --git a/tests/test_create.py b/tests/test_create.py index 66b073cd8..f8249c17d 100644 --- a/tests/test_create.py +++ b/tests/test_create.py @@ -424,12 +424,27 @@ def test_yaml_merge() -> None: c: <<: *A <<: *B - x: 3 + w: 3 z: 1 """ ) ) - assert cfg == {"a": {"x": 1}, "b": {"y": 2}, "c": {"x": 3, "y": 2, "z": 1}} + assert cfg == {"a": {"x": 1}, "b": {"y": 2}, "c": {"x": 1, "y": 2, "w": 3, "z": 1}} + + +def test_yaml_merge_with_conflict() -> None: + with raises(yaml.constructor.ConstructorError): + OmegaConf.create( + dedent( + """\ + a: &A + x: 1 + c: + <<: *A + x: 3 + """ + ) + ) @mark.parametrize(