Skip to content

Commit 865c27f

Browse files
committed
Properly set path and schema_path on nested boolean schemas.
1 parent 0a845d0 commit 865c27f

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎CHANGELOG.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ v4.27.0
55
In particular an applicator with a single subschema now produces the same best match as the bare subschema would.
66
``relevance`` no longer considers an error's position amongst its siblings.
77
When subschemas fail equally deeply, the one which produced fewer errors is now preferred (#1002).
8+
* Errors produced by a ``false`` subschema now have the correct ``path`` and ``schema_path``, rather than empty ones.
89
* Accessing an index with no errors on an ``ErrorTree`` no longer causes that index to appear in the tree (#1328).
910
Subtrees also properly propagate lookup errors which were previously missing when accessing indices not in the subtree.
1011

‎jsonschema/tests/test_validators.py‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,34 @@ def test_boolean_schema_False(self):
13161316
),
13171317
)
13181318

1319+
def test_nested_boolean_schema_False(self):
1320+
schema = {"properties": {"foo": False}}
1321+
validator = validators.Draft7Validator(schema)
1322+
error, = validator.iter_errors({"foo": 12})
1323+
1324+
self.assertEqual(
1325+
(
1326+
error.message,
1327+
error.validator,
1328+
error.validator_value,
1329+
error.instance,
1330+
error.schema,
1331+
error.path,
1332+
error.schema_path,
1333+
error.json_path,
1334+
),
1335+
(
1336+
"False schema does not allow 12",
1337+
None,
1338+
None,
1339+
12,
1340+
False,
1341+
deque(["foo"]),
1342+
deque(["properties", "foo"]),
1343+
"$.foo",
1344+
),
1345+
)
1346+
13191347
def test_ref(self):
13201348
ref, schema = "someRef", {"additionalProperties": {"type": "integer"}}
13211349
validator = validators.Draft7Validator(

‎jsonschema/validators.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,8 @@ def descend(
410410
validator_value=None,
411411
instance=instance,
412412
schema=schema,
413+
path=() if path is None else (path,),
414+
schema_path=() if schema_path is None else (schema_path,),
413415
)
414416
return
415417

0 commit comments

Comments
 (0)