Skip to content

Commit 2f5ff0b

Browse files
committed
Don't blow up if an automatically retrieved resource is missing $schema.
This should possibly default to the specification that the child resource is contained within, but that's actually nontrivial to implement...
1 parent eaf2e7b commit 2f5ff0b

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

CHANGELOG.rst

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ v4.19.0
33

44
* Importing the ``Validator`` protocol directly from the package root is deprecated.
55
Import it from ``jsonschema.protocols.Validator`` instead.
6+
* Automatic retrieval of remote references (which is still deprecated) now properly succeeds even if the retrieved resource does not declare which version of JSON Schema it uses.
7+
Such resources are assumed to be 2020-12 schemas.
8+
This more closely matches the pre-referencing library behavior.
69

710
v4.18.6
811
=======

jsonschema/tests/test_deprecations.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,7 @@ def test_automatic_remote_retrieval(self):
381381
Automatic retrieval of remote references is deprecated as of v4.18.0.
382382
"""
383383
ref = "http://bar#/$defs/baz"
384-
schema = {
385-
"$schema": "https://json-schema.org/draft/2020-12/schema",
386-
"$defs": {"baz": {"type": "integer"}},
387-
}
384+
schema = {"$defs": {"baz": {"type": "integer"}}}
388385

389386
if "requests" in sys.modules: # pragma: no cover
390387
self.addCleanup(

jsonschema/validators.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ def _warn_for_remote_retrieve(uri: str):
119119
DeprecationWarning,
120120
stacklevel=9, # Ha ha ha ha magic numbers :/
121121
)
122-
return referencing.Resource.from_contents(json.load(response))
122+
return referencing.Resource.from_contents(
123+
json.load(response),
124+
default_specification=referencing.jsonschema.DRAFT202012,
125+
)
123126

124127

125128
_REMOTE_WARNING_REGISTRY = SPECIFICATIONS.combine(

0 commit comments

Comments
 (0)