From 5559a31ddf9c45211ef8f15b15a294de14161340 Mon Sep 17 00:00:00 2001 From: Julian Berman Date: Wed, 23 Jan 2019 18:05:31 -0500 Subject: Ensure error properties are properly set for boolean schemas. --- jsonschema/tests/test_validators.py | 21 +++++++++++++++++++++ jsonschema/validators.py | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py index 9624c96..9308e32 100644 --- a/jsonschema/tests/test_validators.py +++ b/jsonschema/tests/test_validators.py @@ -953,6 +953,27 @@ class TestValidationErrorDetails(TestCase): self.assertEqual(error.path, deque([])) self.assertEqual(error.schema_path, deque(["if", "else", "const"])) + def test_boolean_schema_False(self): + validator = validators.Draft7Validator(False) + error, = validator.iter_errors(12) + + self.assertEqual( + ( + error.message, + error.validator, + error.validator_value, + error.instance, + error.schema, + ), + ( + "False schema does not allow 12", + None, + None, + 12, + False, + ), + ) + class MetaSchemaTestsMixin(object): # TODO: These all belong upstream diff --git a/jsonschema/validators.py b/jsonschema/validators.py index 557996a..90c0f1b 100644 --- a/jsonschema/validators.py +++ b/jsonschema/validators.py @@ -270,6 +270,10 @@ def create( elif _schema is False: yield exceptions.ValidationError( "False schema does not allow %r" % (instance,), + validator=None, + validator_value=None, + instance=instance, + schema=_schema, ) return -- cgit v1.2.1