-
Notifications
You must be signed in to change notification settings - Fork 113
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
using YAML merge tag (<<) results in exception #470
Comments
Sorry for the delay -- I missed this notification. It seems like this can be hotfixed by adding a noop-constructor for merge tags like so: diff --git a/omegaconf/_utils.py b/omegaconf/_utils.py
index 1dcf7d9..588b4c8 100644
--- a/omegaconf/_utils.py
+++ b/omegaconf/_utils.py
@@ -129,6 +129,9 @@ def get_yaml_loader() -> Any:
loader.add_constructor(
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, no_duplicates_constructor
)
+ loader.add_constructor(
+ "tag:yaml.org,2002:merge", lambda loader, node, deep=False: None
+ )
return loader For the test case mentioned here, this produces: a:
x: 1
'y': 2
b:
x: 3
'y': 2
z: 1 This looks correct to me, i.e. the value for |
Thanks @jgehring.
Since you are the one that asked (and added) duplicate key validation, I will let you make the call :) |
This adds support for YAML merge tags (<< *ref) while retaining the sanity check for duplicate keys. Note that the [spec for merge keys](https://yaml.org/type/merge.html) explicitly states that keys in the current mapping override the ones in the merged mapping, so the check for duplicates is applied to the current mapping only now. Fixes omry#470.
This adds support for YAML merge tags (<< *ref) while retaining the sanity check for duplicate keys. Note that the spec for merge keys (https://yaml.org/type/merge.html) explicitly states that keys in the current mapping override the ones in the merged mapping. Hence, the check for duplicates is applied to scalar keys of the current mapping only. Fixes omry#470.
Ok, I did some more digging and came up with an IMHO reasonable solution (see PR). It's more or less what the PyYAML maintainer suggested at yaml/pyyaml#165 (comment). |
This adds support for YAML merge tags (<< *ref) while retaining the sanity check for duplicate keys. Note that the spec for merge keys (https://yaml.org/type/merge.html) explicitly states that keys in the current mapping override the ones in the merged mapping. Hence, the check for duplicates is applied to scalar keys of the current mapping only. Fixes omry#470.
This adds support for YAML merge tags (<< *ref) while retaining the sanity check for duplicate keys. Note that the spec for merge keys (https://yaml.org/type/merge.html) explicitly states that keys in the current mapping override the ones in the merged mapping. Hence, the check for duplicates is applied to scalar keys of the current mapping only. Fixes omry#470.
Given that Tina added a bug tag to it a few days ago, maybe they will actually address this in pyyaml eventually. |
This adds support for YAML merge tags (<< *ref) while retaining the sanity check for duplicate keys. Note that the spec for merge keys (https://yaml.org/type/merge.html) explicitly states that keys in the current mapping override the ones in the merged mapping. Hence, the check for duplicates is applied to scalar keys of the current mapping only. Fixes omry#470.
* Support YAML merge tags This adds support for YAML merge tags (<< *ref) while retaining the sanity check for duplicate keys. Note that the spec for merge keys (https://yaml.org/type/merge.html) explicitly states that keys in the current mapping override the ones in the merged mapping. Hence, the check for duplicates is applied to scalar keys of the current mapping only. Fixes #470.
This adds support for YAML merge tags (<< *ref) while retaining the sanity check for duplicate keys. Note that the spec for merge keys (https://yaml.org/type/merge.html) explicitly states that keys in the current mapping override the ones in the merged mapping. Hence, the check for duplicates is applied to scalar keys of the current mapping only. Fixes omry#470.
Describe the bug
This YAML code causes an exception with ``OmegaConf.create()```:
It loads fine with the standard loader
To Reproduce
See above.
Expected behavior
Excpected to load without error.
Additional context
The text was updated successfully, but these errors were encountered: