diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8df86609..69edbd4a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,9 @@ +v4.17.3 +======= + +* Fix instantiating validators with cached refs to boolean schemas + rather than objects (#1018). + v4.17.2 ======= diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py index 8f8680a0..ec76a3e3 100644 --- a/jsonschema/tests/test_validators.py +++ b/jsonschema/tests/test_validators.py @@ -1848,6 +1848,21 @@ class TestDraft202012Validator(ValidatorTestMixin, TestCase): invalid = {"type": "integer"}, "foo" +class TestLatestValidator(TestCase): + """ + These really apply to multiple versions but are easiest to test on one. + """ + + def test_ref_resolvers_may_have_boolean_schemas_stored(self): + ref = "someCoolRef" + schema = {"$ref": ref} + resolver = validators.RefResolver("", {}, store={ref: False}) + validator = validators._LATEST_VERSION(schema, resolver=resolver) + + with self.assertRaises(exceptions.ValidationError): + validator.validate(None) + + class TestValidatorFor(TestCase): def test_draft_3(self): schema = {"$schema": "http://json-schema.org/draft-03/schema"} diff --git a/jsonschema/validators.py b/jsonschema/validators.py index a1322440..66e803ea 100644 --- a/jsonschema/validators.py +++ b/jsonschema/validators.py @@ -4,7 +4,7 @@ from __future__ import annotations from collections import deque -from collections.abc import Sequence +from collections.abc import Mapping, Sequence from functools import lru_cache from operator import methodcaller from urllib.parse import unquote, urldefrag, urljoin, urlsplit @@ -745,7 +745,8 @@ def __init__( self.store.update(store) self.store.update( (schema["$id"], schema) - for schema in store.values() if "$id" in schema + for schema in store.values() + if isinstance(schema, Mapping) and "$id" in schema ) self.store[base_uri] = referrer