AttributeError with wrong payload
We've experimented with your library and ran into an issue when providing a boolean instead of an object (purposedly testing a wrong payload case).
So if we define "information": {"type": "object", ...} but then send a PATCH request with payload {"information": True}, we see the following exception:
File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/rest_framework/mixins.py", line 82, in partial_update
return self.update(request, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/rest_framework/mixins.py", line 67, in update
serializer.is_valid(raise_exception=True)
File "/usr/local/lib/python3.8/site-packages/rest_framework/serializers.py", line 220, in is_valid
self._validated_data = self.run_validation(self.initial_data)
File "/usr/local/lib/python3.8/site-packages/rest_framework/serializers.py", line 419, in run_validation
value = self.to_internal_value(data)
File "/usr/local/lib/python3.8/site-packages/rest_framework/serializers.py", line 476, in to_internal_value
validated_value = field.run_validation(primitive_value)
File "/usr/local/lib/python3.8/site-packages/rest_framework/serializers.py", line 419, in run_validation
value = self.to_internal_value(data)
File "/usr/local/lib/python3.8/site-packages/rest_framework/serializers.py", line 476, in to_internal_value
validated_value = field.run_validation(primitive_value)
File "/usr/local/lib/python3.8/site-packages/rest_framework/fields.py", line 569, in run_validation
self.run_validators(value)
File "/usr/local/lib/python3.8/site-packages/rest_framework/fields.py", line 593, in run_validators
validator(value)
File "/usr/local/lib/python3.8/site-packages/django_validated_jsonfield/serializers.py", line 26, in json_validator
errors = {".".join([self.field_name]+[str(p) for p in error.path]):error.message for error in self.json_validator_cls.iter_errors(value)}
File "/usr/local/lib/python3.8/site-packages/django_validated_jsonfield/serializers.py", line 26, in <dictcomp>
errors = {".".join([self.field_name]+[str(p) for p in error.path]):error.message for error in self.json_validator_cls.iter_errors(value)}
File "/usr/local/lib/python3.8/site-packages/jsonschema/validators.py", line 328, in iter_errors
for error in errors:
File "/usr/local/lib/python3.8/site-packages/django_validated_jsonfield/fields.py", line 32, in set_defaults
for error in validate_properties(
File "/usr/local/lib/python3.8/site-packages/jsonschema/_validators.py", line 282, in properties
for error in validator.descend(
File "/usr/local/lib/python3.8/site-packages/jsonschema/validators.py", line 344, in descend
for error in self.iter_errors(instance, schema):
File "/usr/local/lib/python3.8/site-packages/jsonschema/validators.py", line 328, in iter_errors
for error in errors:
File "/usr/local/lib/python3.8/site-packages/django_validated_jsonfield/fields.py", line 30, in set_defaults
instance.setdefault(property_, subschema["default"])
AttributeError: 'bool' object has no attribute 'setdefault'
We fixed the issue by changing the test protecting instance.setdefault, but there might be a better solution.