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

TypeError: unhashable type: 'list' with jsonschema v4.7.1 #973

Closed
michaelschmit opened this issue Jul 11, 2022 · 5 comments
Closed

TypeError: unhashable type: 'list' with jsonschema v4.7.1 #973

michaelschmit opened this issue Jul 11, 2022 · 5 comments

Comments

@michaelschmit
Copy link

When using the latest jsonschema v4.7.1, I am seeing the following error during schema validation:

../venv/lib/python3.9/site-packages/jsonschema/validators.py:1057: in validate
error = exceptions.best_match(validator.iter_errors(instance))
../venv/lib/python3.9/site-packages/jsonschema/exceptions.py:377: in best_match
best = max(itertools.chain([best], errors), key=key)
../venv/lib/python3.9/site-packages/jsonschema/exceptions.py:327: in relevance
not error._matches_type(),
../venv/lib/python3.9/site-packages/jsonschema/exceptions.py:150: in _matches_type
return self._type_checker.is_type(self.instance, expected_type)
../venv/lib/python3.9/site-packages/jsonschema/_types.py:118: in is_type
fn = self._type_checkers[type]
../venv/lib/python3.9/site-packages/pyrsistent/_pmap.py:70: in getitem
return PMap._getitem(self._buckets, key)
../venv/lib/python3.9/site-packages/pyrsistent/_pmap.py:61: in _getitem
_, bucket = PMap._get_bucket(buckets, key)


buckets = pvector([[('string', <function is_string at 0x10dd50e50>)], None, [('object', <function is_object at 0x10dd50dc0>)], [...e, [('null', <function is_null at 0x10dd50ca0>)], [('integer', <function at 0x10dd50f70>)], None, None, None])
key = ['string', 'null']

@staticmethod
def _get_bucket(buckets, key):
  index = hash(key) % len(buckets)

E TypeError: unhashable type: 'list'

If I go back and target v4.6.2 this issue does not occur. It appears all instances where this issue is occurring is on validation failures when using regex pattern validation. I will try to put together a simplified example of this issue.

@michaelschmit
Copy link
Author

michaelschmit commented Jul 11, 2022

During creation of a simplified example, I have located the crux of the issue. Per the json schema spec, a type can be a single primitive which is represented by a string or multiple primitives which is represented by an array. It seems that with the latest update, jsonschema cannot handle an array being specified.

Spec link:
https://json-schema.org/draft/2020-12/json-schema-core.html#name-assertions-and-instance-pri

"... also includes a "type" keyword which can independently restrict the instance to one or more primitive types. This allows for a concise expression of use cases such as a function that might return either a string of a certain length or a null value:

{
"type": ["string", "null"],
"maxLength": 255
}"

Adding a mention for @Julian since that is who performed the commit.

@Julian
Copy link
Member

Julian commented Jul 12, 2022

Hi. Please share some code which produces the error.

@Julian Julian closed this as completed in 72c3200 Jul 12, 2022
@Julian
Copy link
Member

Julian commented Jul 12, 2022

Never mind, I think I see what you're running. Thanks for the report, I believe v4.7.2 will fix what you have when it's released in a few minutes.

@michaelschmit
Copy link
Author

Yes, the issue is resolved. I appreciate the quick turn around. I apologize for not providing a full working proof.

hswong3i pushed a commit to alvistack/python-jsonschema-jsonschema that referenced this issue Jul 12, 2022
@Julian
Copy link
Member

Julian commented Jul 12, 2022

No problem, thanks again.

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

2 participants