You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected behavior:
The request should be processed successfully, even if the string field is left empty, since required=False is specified for the field.
Actual behavior:
The request fails, and a validation error is returned, indicating that the string field is required, despite setting required=False.
Additional information:
I've tested this issue on django_jsonform version 2.17.1, using Python 3.8.10 and Django 3.2.18
Yes, this is kind of a "known" issue at this point.
As per the JSON Schema spec, all properties are optional by default. But I've chosen not to follow that rule and instead stick to how things work in Django.
E.g., even if a field is not required, such as — name = models.CharField(required=False) — Django will still insert an empty string in the database.
So, we interpret the required keyword as to whether this field (key) can be empty or not.
But we still require that the submitted data must contain all the keys which are declared in the schema.
So, the built-in JSONSchemaValidator will consider this valid: {"required_field": "", "non_required_field": ""}
Description:
Expected behavior:
The request should be processed successfully, even if the string field is left empty, since
required=False
is specified for the field.Actual behavior:
The request fails, and a validation error is returned, indicating that the string field is required, despite setting
required=False
.Additional information:
I've tested this issue on django_jsonform version 2.17.1, using Python 3.8.10 and Django 3.2.18
Relevant code snippets:
This throws an exception, saying:
These fields are missing from the data: non_required_field is required.
It's possible that the issue lies within the validation process or the way the JSON schema is handled.
Please let me know if there's any additional information required or if you have further questions.
The text was updated successfully, but these errors were encountered: