Skip to content

Relative $refs crash when $id is a URN or other custom scheme #544

@dstokesf5

Description

@dstokesf5

Using a URN for the $id property in a schema is causing many URL related errors:

Traceback (most recent call last):
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/lib/python3.7/site-packages/jsonschema/validators.py", line 739, in resolve_from_url
    document = self.store[url]
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/lib/python3.7/site-packages/jsonschema/_utils.py", line 23, in __getitem__
    return self.store[self.normalize(uri)]
KeyError: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/lib/python3.7/site-packages/jsonschema/validators.py", line 742, in resolve_from_url
    document = self.resolve_remote(url)
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/lib/python3.7/site-packages/jsonschema/validators.py", line 828, in resolve_remote
    with urlopen(uri) as url:
  File "/usr/lib64/python3.7/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib64/python3.7/urllib/request.py", line 510, in open
    req = Request(fullurl, data)
  File "/usr/lib64/python3.7/urllib/request.py", line 328, in __init__
    self.full_url = url
  File "/usr/lib64/python3.7/urllib/request.py", line 354, in full_url
    self._parse()
  File "/usr/lib64/python3.7/urllib/request.py", line 383, in _parse
    raise ValueError("unknown url type: %r" % self.full_url)
ValueError: unknown url type: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/bin/jsonschema", line 10, in <module>
    sys.exit(main())
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/lib/python3.7/site-packages/jsonschema/cli.py", line 67, in main
    sys.exit(run(arguments=parse_args(args=args)))
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/lib/python3.7/site-packages/jsonschema/cli.py", line 78, in run
    for error in validator.iter_errors(instance):
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/lib/python3.7/site-packages/jsonschema/validators.py", line 323, in iter_errors
    for error in errors:
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/lib/python3.7/site-packages/jsonschema/_validators.py", line 303, in allOf
    for error in validator.descend(instance, subschema, schema_path=index):
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/lib/python3.7/site-packages/jsonschema/validators.py", line 339, in descend
    for error in self.iter_errors(instance, schema):
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/lib/python3.7/site-packages/jsonschema/validators.py", line 323, in iter_errors
    for error in errors:
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/lib/python3.7/site-packages/jsonschema/_validators.py", line 247, in ref
    scope, resolved = validator.resolver.resolve(ref)
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/lib/python3.7/site-packages/jsonschema/validators.py", line 734, in resolve
    return url, self._remote_cache(url)
  File "/pdhome/dstokes/dev/f5-appsvcs/venv/lib/python3.7/site-packages/jsonschema/validators.py", line 744, in resolve_from_url
    raise exceptions.RefResolutionError(exc)
jsonschema.exceptions.RefResolutionError: unknown url type: ''

This is possibly a duplicate of #313, but I cannot reproduce this without a URN $id.

Schema:

{
    "$id": "urn:uuid:85626792-9ee7-46bb-8fc8-4ba708cfdc1d",
    "allOf": [
        { "$ref": "#/definitions/schema" }
    ],
    "definitions": {
        "schema": {}
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething doesn't work the way it should.Needs Test UpstreamIssues that need to have a test added to https://github.com/json-schema-org/JSON-Schema-Test-Suite

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions