Skip to content

AttributeError: 'Registry' object has no attribute 'resolving'. Did you mean: 'resolver'? #1352

@t1m013y

Description

@t1m013y

I am making test code that validates JSON by schema. When I run it, the error occurs:

AttributeError: 'Registry' object has no attribute 'resolving'. Did you mean: 'resolver'?

Is it the library issue or do I do something wrong?

Code:

import json

import jsonschema
import referencing


def main():
    with open('data.json', 'r') as f:
        json_data = json.load(f)

    with open('schema.json', 'r') as f:
        json_schema = json.load(f)

    print("Json data:", json_data, sep='\n')

    res = referencing.Resource.from_contents(json_schema)
    reg = referencing.Registry().with_resource(res.id(), res).crawl()

    jsonschema.validate(json_data,
                        reg["https://t1m013y.github.io/jsonschema/test_person"].contents,
                        None,
                        reg)


if __name__ == '__main__':
    main()

schema.json:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://t1m013y.github.io/jsonschema/test001.json",
  "$defs": {
    "nonNegativeInt": {
      "$id": "https://t1m013y.github.io/jsonschema/test_nonNegativeInt",
      "type": "integer",
      "minimum": 0
    },
    "person": {
      "$id": "https://t1m013y.github.io/jsonschema/test_person",
      "properties": {
        "name": {"type":  "string"},
        "age": {"$ref": "https://t1m013y.github.io/jsonschema/test_nonNegativeInt"}
      }
    }
  }
}

data.json:

{
  "name": "John",
  "age": 3
}

Full error log:

F:\WinPython\python\python.exe F:\PycharmProjects\test_jsonReferencing_001\test001.py 
Json data:
{'name': 'John', 'age': 3}
Traceback (most recent call last):
  File "F:\PycharmProjects\test_jsonReferencing_001\test001.py", line 26, in <module>
    main()
    ~~~~^^
  File "F:\PycharmProjects\test_jsonReferencing_001\test001.py", line 19, in main
    jsonschema.validate(json_data,
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
                        reg["https://t1m013y.github.io/jsonschema/test_person"].contents,
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        None,
                        ^^^^^
                        reg)
                        ^^^^
  File "F:\WinPython\python\Lib\site-packages\jsonschema\validators.py", line 1330, in validate
    error = exceptions.best_match(validator.iter_errors(instance))
  File "F:\WinPython\python\Lib\site-packages\jsonschema\exceptions.py", line 475, in best_match
    best = next(errors, None)
  File "F:\WinPython\python\Lib\site-packages\jsonschema\validators.py", line 384, in iter_errors
    for error in errors:
                 ^^^^^^
  File "F:\WinPython\python\Lib\site-packages\jsonschema\_keywords.py", line 296, in properties
    yield from validator.descend(
    ...<4 lines>...
    )
  File "F:\WinPython\python\Lib\site-packages\jsonschema\validators.py", line 432, in descend
    for error in errors:
                 ^^^^^^
  File "F:\WinPython\python\Lib\site-packages\jsonschema\_keywords.py", line 275, in ref
    yield from validator._validate_reference(ref=ref, instance=instance)
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "F:\WinPython\python\Lib\site-packages\jsonschema\validators.py", line 475, in _validate_reference
    with self._ref_resolver.resolving(ref) as resolved:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Registry' object has no attribute 'resolving'. Did you mean: 'resolver'?

Process finished with exit code 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions