#35259: forms.JSONField validator doesn't match documentation behavior
-----------------------------------------+---------------------------
Reporter: jklingen92 | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 5.0
Severity: Normal | Keywords: JSONField
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-----------------------------------------+---------------------------
If you have a required JSONField on a model and you make a model form, the
model form rejects falsey values as empty ([] for sure, possibly others as
well). The documentation says that None is the empty value for the
forms.JSONField.
I've seen similar documented issues with regards to the admin panel, not
sure if they're running off the same code or not, but it doesn't seem to
be resolved in this case.
For example:
{{{
class FooForm(forms.Form)
bar = forms.JSONField(required=True)
# in shell
f = FooForm(data={"bar": []})
f.is_valid() # False
f.errors # {'bar': ['This field is required.']}
}}}
This contradicts the documentation, as well as the behavior of the JSON
model field, so that JSON fields create undesirable behavior in
ModelForms.
I'm using Django 3.2, not sure if this behavior is fixed in a later
version.
--
Ticket URL: <https://code.djangoproject.com/ticket/35259>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/0107018def7e9ba1-e7f72993-a3bd-4db0-a568-0399846e41f2-000000%40eu-central-1.amazonses.com.