Skip to content

Commit

Permalink
Fix an additional regression with RefResolver and pointer resolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Jul 12, 2023
1 parent 90ea779 commit 52c2419
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v4.18.2
=======

* Fix an additional regression with the deprecated ``jsonschema.RefResolver`` and pointer resolution.

v4.18.1
=======

Expand Down
19 changes: 19 additions & 0 deletions jsonschema/tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2394,6 +2394,25 @@ def handle(uri):
(False, True),
)

def test_refresolver_with_pointer_in_schema_with_no_id(self):
"""
See https://github.com/python-jsonschema/jsonschema/issues/1124#issuecomment-1632574249.
""" # noqa: E501

schema = {
"properties": {"x": {"$ref": "#/definitions/x"}},
"definitions": {"x": {"type": "integer"}},
}

validator = validators.Draft202012Validator(
schema,
resolver=validators._RefResolver("", schema),
)
self.assertEqual(
(validator.is_valid({"x": "y"}), validator.is_valid({"x": 37})),
(False, True),
)



def sorted_errors(errors):
Expand Down
4 changes: 3 additions & 1 deletion jsonschema/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ def __attrs_post_init__(self):
# REMOVEME: Legacy ref resolution state management.
push_scope = getattr(self._ref_resolver, "push_scope", None)
if push_scope is not None:
push_scope(id_of(self.schema))
id = id_of(self.schema)
if id is not None:
push_scope(id)

@classmethod
def check_schema(cls, schema, format_checker=_UNSET):
Expand Down

0 comments on commit 52c2419

Please sign in to comment.