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

Plain equal sign (=) as node content results in an error #89

Open
rdn32 opened this issue Oct 20, 2017 · 3 comments · May be fixed by #635
Open

Plain equal sign (=) as node content results in an error #89

rdn32 opened this issue Oct 20, 2017 · 3 comments · May be fixed by #635

Comments

@rdn32
Copy link

rdn32 commented Oct 20, 2017

Running this code:

import yaml
print(yaml.load("="))

Gives this error:
yaml.constructor.ConstructorError: could not determine a constructor for the tag 'tag:yaml.org,2002:value' in "<string>", line 1, column 1: = ^

There was, in the past, a ticket against PyYAML; but I suspect it got lost in a migration. See https://web.archive.org/web/20100707124750/http://pyyaml.org:80/ticket/140

The SnakeYAML people had a discussion of correct behaviour in this sort of situation at https://code.google.com/archive/p/snakeyaml/issues/192, the conclusion of which was (loosely paraphrased) "an equals sign is unambiguously a string value, and so doesn't need quoting, provided that you ignore the Value Key Language-Independent Type facility which never really worked anyway."

The equivalent fix to the one in SnakeYAML would be to remove the following lines from resolver.py:

Resolver.add_implicit_resolver(
        u'tag:yaml.org,2002:value',
        re.compile(ur'^(?:=)$'),
        [u'='])

I've also found it is possible to work around the issue with the following:

def construct_value(load, node):
    if not isinstance(node, yaml.ScalarNode):
        raise yaml.constructor.ConstructorError(
            "while constructing a value",
            node.start_mark,
            "expected a scalar, but found %s" % node.id, node.start_mark
        )
    yield str(node.value)

yaml.Loader.add_constructor(u'tag:yaml.org,2002:value', construct_value)
@stuart-warren
Copy link

we are hitting this too

willthames added a commit to willthames/kubernetes-validate that referenced this issue Jan 18, 2022
workaround yaml/pyyaml#89

Allow `-` as a filename to read from stdin
@jonapich
Copy link

Since the bug is that = is assigned tag:yaml.org,2002:value even though there's no constructor for it, a simple fix is to pop that one from your loader:

Loader.yaml_implicit_resolvers.pop("=")

You can isolate the fix to your own loader too:

class PatchedFullLoader(FullLoader):
    yaml_implicit_resolvers = FullLoader.yaml_implicit_resolvers.copy()
    yaml_implicit_resolvers.pop("=")

@jonapich jonapich linked a pull request May 11, 2022 that will close this issue
allenporter added a commit to allenporter/k8s-gitops that referenced this issue Sep 4, 2022
felixscheinost added a commit to felixscheinost/kubenix that referenced this issue Jun 15, 2023
Remarshal doesn’t seem to be maintained anymore.

It is also affected by upstream bugs like yaml/pyyaml#89 which affects e.g. prometheus-operator CRDs.
felixscheinost added a commit to felixscheinost/kubenix that referenced this issue Jun 15, 2023
Remarshal doesn’t seem to be maintained anymore.

It is also affected by upstream bugs like yaml/pyyaml#89 which affects e.g. prometheus-operator CRDs.
felixscheinost added a commit to felixscheinost/kubenix that referenced this issue Jun 15, 2023
Remarshal doesn’t seem to be maintained anymore.

It is also affected by upstream bugs like yaml/pyyaml#89 which affects e.g. prometheus-operator CRDs.
felixscheinost added a commit to felixscheinost/kubenix that referenced this issue Jun 15, 2023
Remarshal doesn’t seem to be maintained anymore.

It is also affected by upstream bugs like yaml/pyyaml#89 which affects e.g. prometheus-operator CRDs.
felixscheinost added a commit to felixscheinost/kubenix that referenced this issue Jun 15, 2023
Remarshal doesn’t seem to be maintained anymore.

It is also affected by upstream bugs like yaml/pyyaml#89 which affects e.g. prometheus-operator CRDs.
felixscheinost added a commit to felixscheinost/kubenix that referenced this issue Jun 15, 2023
Remarshal doesn’t seem to be maintained anymore.

It is also affected by upstream bugs like yaml/pyyaml#89 which affects e.g. prometheus-operator CRDs.
felixscheinost added a commit to felixscheinost/kubenix that referenced this issue Jun 15, 2023
Remarshal doesn’t seem to be maintained anymore.

It is also affected by upstream bugs like yaml/pyyaml#89 which affects e.g. prometheus-operator CRDs.
felixscheinost added a commit to felixscheinost/kubenix that referenced this issue Jun 15, 2023
Remarshal doesn’t seem to be maintained anymore.

It is also affected by upstream bugs like yaml/pyyaml#89 which affects e.g. prometheus-operator CRDs.
felixscheinost added a commit to felixscheinost/kubenix that referenced this issue Jun 16, 2023
Remarshal doesn’t seem to be maintained anymore.

It is also affected by upstream bugs like yaml/pyyaml#89 which affects e.g. prometheus-operator CRDs.
hall pushed a commit to hall/kubenix that referenced this issue Jun 19, 2023
Remarshal doesn’t seem to be maintained anymore.

It is also affected by upstream bugs like yaml/pyyaml#89 which affects e.g. prometheus-operator CRDs.
@krichter722
Copy link

Has someone bisected this issue yet and can share a range of versions which are affected (probably open end because the issues isn't fixed yet)? I see this issue is being referenced as upstream issue by a lot of bugs, among them some Helm Charts rolled out with Ansible. The version range helps in mitigating downstream issues - a fix is very welcome as well of course. I guess they affected pyyaml version has made it in a lot of downstream tools. In there environment it's impossible or hard to apply the workaround (thanks) without ugly patches.

skwashd added a commit to proactiveops/picofun that referenced this issue Jun 17, 2024
skwashd added a commit to proactiveops/picofun that referenced this issue Jun 17, 2024
skwashd added a commit to proactiveops/picofun that referenced this issue Jun 17, 2024
NiklasRosenstein added a commit to NiklasRosenstein/nyl that referenced this issue Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants