You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've found some weird bug: calling revalidate() for the second time raises an Invalid state exception when optional fields with default values are present in the schema, but not in the YAML document. Here's a snippet to reproduce the problem.
fromstrictyamlimportload, Map, Int, Optionaldoc="x: 1"# This works fineschema=Map({ "x": Int(), Optional("y"): Int() })
yaml=load(doc, schema)
try:
foriinrange(1,6):
yaml.revalidate(schema)
print(i, end=" ")
exceptExceptionase:
print(e)
print("")
# This raises an exception on the second iterationschema=Map({ "x": Int(), Optional("y", default=42): Int() })
yaml=load(doc, schema)
try:
foriinrange(1,6):
yaml.revalidate(schema)
print(i, end=" ")
exceptExceptionase:
print(e)
The generated output:
1 2 3 4 5
1 Invalid state
It seems that the type of the field does not matter: I've got the same behavior for Str and Any.
On the other hand, the exception is not raised when the YAML object is modified, either by removing the optional value or modifying another one i.e. no exception is raised by the following loops
It looks like adding default keys scrambles the order of the state of the YAMLChunk object, leading to inconsistency between the ruamel parsing and the strictyaml parsing. This is the same outcome as in #184, where a failed revalidation leads to inconsistency. In the original example:
Guess it can be worked around by non revalidating... but...
Otherwise, I wonder if dealing with optional stuff by using a MapCombined and to then explicitly look for some keys and add them with the default values if missing would cause the same issue.
But in fact, would be glad to know if a fix is possible or far away in a pipeline of more urgent stuff...
I've found some weird bug: calling
revalidate()
for the second time raises anInvalid state
exception when optional fields with default values are present in the schema, but not in the YAML document. Here's a snippet to reproduce the problem.The generated output:
It seems that the type of the field does not matter: I've got the same behavior for
Str
andAny
.On the other hand, the exception is not raised when the YAML object is modified, either by removing the optional value or modifying another one i.e. no exception is raised by the following loops
It looks to me that
revalidate()
uses some internal values that are reset whenever the YAML object is modified, but not otherwise.The text was updated successfully, but these errors were encountered: