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

Failed revalidation leads to inconsistant state #184

Open
aschankler opened this issue May 31, 2022 · 0 comments
Open

Failed revalidation leads to inconsistant state #184

aschankler opened this issue May 31, 2022 · 0 comments

Comments

@aschankler
Copy link

Incomplete revalidation also causes a mismatch between the ruamel and strictyaml internal states in the YAMLChunk object. This is the same outcome as in #183, but the initial cause of the inconsistency is different, so I've listed this as a separate issue.

An example of the error:

from strictyaml import Int, Map, Str, as_document

dat = {"a": 1, "b": "x"}
schema1 = Map({"a": Int(), "b": Int()})
schema2 = Map({"a": Int(), "b": Str()})

# The state is consistent here
yml._chunk.contents
# ordereddict([('a', '1'), ('b', 'x')])
yml._chunk.strictparsed()
# ordereddict([(YAML(a), YAML(1)), (YAML(b), YAML(x))])

yml.revalidate(schema1)
# Fails (as it should)

# But the state is now inconsistent
yml._chunk.contents
# ordereddict([('a', '1'), ('b', 'x')])
yml._chunk.strictparsed()
# ordereddict([(YAML(b), YAML(x)), (YAML(a), YAML(1))])

The mismatch in the internal state means that revalidation with a correct schema will fail:

yml.revalidate(schema2)
...
strictyaml.exceptions.YAMLValidationError: when expecting an integer
found arbitrary text
  in "<unicode string>", line 2, column 1:
    b: x
    ^ (line: 2)
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

No branches or pull requests

1 participant