Skip to content

Commit dbc3982

Browse files
committed
Fix instantiating validators with cached refs-to-bool schemas.
Closes: #1018
1 parent 7ebe161 commit dbc3982

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

CHANGELOG.rst

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v4.17.3
2+
=======
3+
4+
* Fix instantiating validators with cached refs to boolean schemas
5+
rather than objects (#1018).
6+
17
v4.17.2
28
=======
39

jsonschema/tests/test_validators.py

+15
Original file line numberDiff line numberDiff line change
@@ -1848,6 +1848,21 @@ class TestDraft202012Validator(ValidatorTestMixin, TestCase):
18481848
invalid = {"type": "integer"}, "foo"
18491849

18501850

1851+
class TestLatestValidator(TestCase):
1852+
"""
1853+
These really apply to multiple versions but are easiest to test on one.
1854+
"""
1855+
1856+
def test_ref_resolvers_may_have_boolean_schemas_stored(self):
1857+
ref = "someCoolRef"
1858+
schema = {"$ref": ref}
1859+
resolver = validators.RefResolver("", {}, store={ref: False})
1860+
validator = validators._LATEST_VERSION(schema, resolver=resolver)
1861+
1862+
with self.assertRaises(exceptions.ValidationError):
1863+
validator.validate(None)
1864+
1865+
18511866
class TestValidatorFor(TestCase):
18521867
def test_draft_3(self):
18531868
schema = {"$schema": "http://json-schema.org/draft-03/schema"}

jsonschema/validators.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from __future__ import annotations
55

66
from collections import deque
7-
from collections.abc import Sequence
7+
from collections.abc import Mapping, Sequence
88
from functools import lru_cache
99
from operator import methodcaller
1010
from urllib.parse import unquote, urldefrag, urljoin, urlsplit
@@ -745,7 +745,8 @@ def __init__(
745745
self.store.update(store)
746746
self.store.update(
747747
(schema["$id"], schema)
748-
for schema in store.values() if "$id" in schema
748+
for schema in store.values()
749+
if isinstance(schema, Mapping) and "$id" in schema
749750
)
750751
self.store[base_uri] = referrer
751752

0 commit comments

Comments
 (0)