unevaluatedProperties error gets raised before more relevant validation errors #1132
Labels
Enhancement
Some new desired functionality
Error Reporting
Issues related to clearer or more robust validation error reporting
Hello!
I noticed that in schemas using 'allOf' and unevaluatedProperties, when there is an error in a subschema, instead of showing the relevant error, unevaluatedProperties is (sometimes?) shown instead. This makes it really hard to see what went wrong in anything larger than trivial examples. This seems to be related to #1074, just with a different scenario.
Here is a small example:
Which produces the error trace:
If I validate instead using:
Then the raised error is much more helpful:
Seems like this happens because
jsonschema.validate
is equivalent toraise best_match(jsonschema.Draft202012Validator(schema).iter_errors(obj))
in this case, and thebest_match
heuristic downgrades any errors coming from 'allOf' and 'oneOf'.With a more complex schema, I get an unevaluatedProperties error using both approaches.
3 ways of going about it could be:
The suggestion from Friendlier
unevaluatedProperties
errors #1074 to separately keep track of unevaluated properties and invalid properties, and write different error messages for them.Add properties to evaluated keys even if there are errors resulting from
validator.descend
in https://github.com/python-jsonschema/jsonschema/blob/main/jsonschema/_utils.py:This way unevaluatedProperties will not get raised for properties with subschema errors at all (which shouldn't be a problem, because it'll get raised when those errors are fixed).
unevaluatedProperties
messages even weaker than "allOf" and "anyOf" related errors in https://github.com/python-jsonschema/jsonschema/blob/main/jsonschema/exceptions.py#L19I'd be happy to attempt a PR; do you have any thoughts about which approach is best?
The text was updated successfully, but these errors were encountered: