Skip to content

Commit 52c2419

Browse files
committed
Fix an additional regression with RefResolver and pointer resolution.
Closes: #1124
1 parent 90ea779 commit 52c2419

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

CHANGELOG.rst

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v4.18.2
2+
=======
3+
4+
* Fix an additional regression with the deprecated ``jsonschema.RefResolver`` and pointer resolution.
5+
16
v4.18.1
27
=======
38

jsonschema/tests/test_validators.py

+19
Original file line numberDiff line numberDiff line change
@@ -2394,6 +2394,25 @@ def handle(uri):
23942394
(False, True),
23952395
)
23962396

2397+
def test_refresolver_with_pointer_in_schema_with_no_id(self):
2398+
"""
2399+
See https://github.com/python-jsonschema/jsonschema/issues/1124#issuecomment-1632574249.
2400+
""" # noqa: E501
2401+
2402+
schema = {
2403+
"properties": {"x": {"$ref": "#/definitions/x"}},
2404+
"definitions": {"x": {"type": "integer"}},
2405+
}
2406+
2407+
validator = validators.Draft202012Validator(
2408+
schema,
2409+
resolver=validators._RefResolver("", schema),
2410+
)
2411+
self.assertEqual(
2412+
(validator.is_valid({"x": "y"}), validator.is_valid({"x": 37})),
2413+
(False, True),
2414+
)
2415+
23972416

23982417

23992418
def sorted_errors(errors):

jsonschema/validators.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ def __attrs_post_init__(self):
278278
# REMOVEME: Legacy ref resolution state management.
279279
push_scope = getattr(self._ref_resolver, "push_scope", None)
280280
if push_scope is not None:
281-
push_scope(id_of(self.schema))
281+
id = id_of(self.schema)
282+
if id is not None:
283+
push_scope(id)
282284

283285
@classmethod
284286
def check_schema(cls, schema, format_checker=_UNSET):

0 commit comments

Comments
 (0)