Skip to content

Failed revalidation leads to inconsistant state #184

Open
@aschankler

Description

@aschankler

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions