Skip to content

Commit

Permalink
Fix instantiating validators with cached refs-to-bool schemas.
Browse files Browse the repository at this point in the history
Closes: #1018
  • Loading branch information
Julian committed Nov 29, 2022
1 parent 7ebe161 commit dbc3982
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
6 changes: 6 additions & 0 deletions 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
=======

Expand Down
15 changes: 15 additions & 0 deletions jsonschema/tests/test_validators.py
Expand Up @@ -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"}
Expand Down
5 changes: 3 additions & 2 deletions jsonschema/validators.py
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit dbc3982

Please sign in to comment.