SystemError: <method 'validate' of 'jsonschema_rs.JSONSchema' objects> returned a result with an exception set
Closed this issue · 3 comments
ermakov-oleg commented
Prerequisites
- jsonschema-rs version: 0.16.0
- Python version: 3.10.2
- Operating System: macos
Description
System error when trying to check dict with numeric keys.
Example:
from jsonschema_rs import JSONSchema
schema = JSONSchema({'type': 'object', 'additionalProperties': {'type': 'string'}})
schema.validate({123: "123"})
Result:
TypeError: bad argument type for built-in operation
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "...../test.py", line 5, in <module>
schema.validate({123: "123"})
SystemError: <method 'validate' of 'jsonschema_rs.JSONSchema' objects> returned a result with an exception set
Process finished with exit code 1
Expected behavior
Validation error or pass validation
Stranger6667 commented
Hi @ermakov-oleg.
Yeah, it would be much better to improve the error message & exception itself. The issue is that the underlying Rust crate works only with JSON, which supports only string keys. Generally, the library expects the caller to provide data that matches the JSON semantics.
ermakov-oleg commented
Yes, returning false in is_valid
method or throwing an exception in iter_errors
would be a good solution.
I'll try in my spare time to see how this can be fixed.
Stranger6667 commented
The fix is released in 0.16.1