Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot compile some schemas in v1.5 #12

Closed
gmaclean opened this issue Jun 20, 2018 · 3 comments
Closed

Cannot compile some schemas in v1.5 #12

gmaclean opened this issue Jun 20, 2018 · 3 comments

Comments

@gmaclean
Copy link

gmaclean commented Jun 20, 2018

When attempting to compile some schemas, the following stack trace is encountered:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/fastjsonschema/__init__.py", line 80, in compile
    resolver = RefResolver.from_schema(definition, handlers=handlers)
  File "/usr/local/lib/python3.5/dist-packages/fastjsonschema/ref_resolver.py", line 109, in from_schema
    return cls(schema.get('id', ''), schema, handlers=handlers, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/fastjsonschema/ref_resolver.py", line 98, in __init__
    self.walk(schema)
  File "/usr/local/lib/python3.5/dist-packages/fastjsonschema/ref_resolver.py", line 180, in walk
    self.walk(item)
  File "/usr/local/lib/python3.5/dist-packages/fastjsonschema/ref_resolver.py", line 173, in walk
    self.store[normalize(self.resolution_scope)] = node
  File "/usr/local/lib/python3.5/dist-packages/fastjsonschema/ref_resolver.py", line 45, in normalize
    return urlparse.urlsplit(uri).geturl()
  File "/usr/lib/python3.5/urllib/parse.py", line 328, in urlsplit
    url, scheme, _coerce_result = _coerce_args(url, scheme)
  File "/usr/lib/python3.5/urllib/parse.py", line 115, in _coerce_args
    return _decode_args(args) + (_encode_result,)
  File "/usr/lib/python3.5/urllib/parse.py", line 99, in _decode_args
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
  File "/usr/lib/python3.5/urllib/parse.py", line 99, in <genexpr>
    return tuple(x.decode(encoding, errors) if x else '' for x in args)
AttributeError: 'dict' object has no attribute 'decode'

...I am still trying to get more information about the schemas that cause this.

Example code to trigger problem:

import fastjsonschema
schema = {
  "type": "object",
  "properties": {
    "id": {"type": "integer"}
  }
}
fastjsonschema.compile(schema)

This appears to be introduced in 1.5; not encountered in 1.4.

@gmaclean gmaclean changed the title Cannot compile schema with type "object" in v1.5 Cannot compile some schemas in v1.5 Jun 20, 2018
@Jokipii
Copy link
Contributor

Jokipii commented Jun 21, 2018

Thanks for report!

RefResolver bug: It tries to use 'id' property for URI resolution, even it is not actual schema 'id'.

I will commit a fix...

@horejsek
Copy link
Owner

Fix by @Jokipii merged. Will release it later today.

@gmaclean
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants