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

yaml.constructor.ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:value' #683

Closed
aleksandr-vin opened this issue Dec 4, 2022 · 5 comments
Labels

Comments

@aleksandr-vin
Copy link

The yaml doc

op: =

is not loading:

(venv) % pip install pyyaml
Collecting pyyaml
  Using cached PyYAML-6.0-cp310-cp310-macosx_11_0_arm64.whl (173 kB)
Installing collected packages: pyyaml
Successfully installed pyyaml-6.0
(venv) % python -c "import yaml ; yaml.load_safe('op: = ')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'yaml' has no attribute 'load_safe'. Did you mean: 'load_all'?
(venv) % python -c "import yaml ; yaml.safe_load('op: = ')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/tmp/venv/lib/python3.10/site-packages/yaml/__init__.py", line 125, in safe_load
    return load(stream, SafeLoader)
  File "/private/tmp/venv/lib/python3.10/site-packages/yaml/__init__.py", line 81, in load
    return loader.get_single_data()
  File "/private/tmp/venv/lib/python3.10/site-packages/yaml/constructor.py", line 51, in get_single_data
    return self.construct_document(node)
  File "/private/tmp/venv/lib/python3.10/site-packages/yaml/constructor.py", line 60, in construct_document
    for dummy in generator:
  File "/private/tmp/venv/lib/python3.10/site-packages/yaml/constructor.py", line 413, in construct_yaml_map
    value = self.construct_mapping(node)
  File "/private/tmp/venv/lib/python3.10/site-packages/yaml/constructor.py", line 218, in construct_mapping
    return super().construct_mapping(node, deep=deep)
  File "/private/tmp/venv/lib/python3.10/site-packages/yaml/constructor.py", line 143, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
  File "/private/tmp/venv/lib/python3.10/site-packages/yaml/constructor.py", line 100, in construct_object
    data = constructor(self, node)
  File "/private/tmp/venv/lib/python3.10/site-packages/yaml/constructor.py", line 427, in construct_undefined
    raise ConstructorError(None, None,
yaml.constructor.ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:value'
  in "<unicode string>", line 1, column 5:
    op: =
        ^
@aleksandr-vin
Copy link
Author

I reported an issue initially on pre-commit/pre-commit-hooks#846 but it looks like its place is here

@nitzmahone
Copy link
Member

nitzmahone commented Dec 7, 2022

It looks like you're running afoul of this: https://yaml.org/type/value.html. Short answer is "quote the equals or prefix it with !!str if you want it to work in current PyYAML as a string", since this appears at first blush to be one of those 1.1-side-spec-isms that doesn't have an analogue in 1.2 and PyYAML is mostly 1.1, but someone that's more of a spec expert might correct me if I'm wrong.

@aleksandr-vin
Copy link
Author

Thanks @nitzmahone.

I'm getting that yaml part in the process of converting a json data into yaml, with the pipeline like this:

echo '{"op":"="}' | yq -P eval

And the json I receive from Grafana's /api/dashboards/uid/{uid} api call. So it's not easy/tidy to quote or prefix the value.

@perlpunk
Copy link
Member

Duplicate of #89

@perlpunk perlpunk marked this as a duplicate of #89 Dec 29, 2022
@perlpunk perlpunk closed this as not planned Won't fix, can't repro, duplicate, stale Dec 29, 2022
@nitzmahone
Copy link
Member

@perlpunk yay for dupe issue necromancy 😆

@aleksandr-vin If you can do things in the Python environment before the document is loaded, the following awful hack will let all subsequent document parses succeed in the presence of a value like that:

del(yaml.resolver.Resolver.yaml_implicit_resolvers['='])

Longer-term, especially since it doesn't look like that type ever really fulfilled its promise, seems like we might want to nuke it.

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

3 participants