strictyaml icon indicating copy to clipboard operation
strictyaml copied to clipboard

Failed revalidation leads to inconsistant state

Open aschankler opened this issue 2 years ago • 0 comments

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)

aschankler avatar May 31 '22 02:05 aschankler