Opened 4 years ago
Closed 4 years ago
#32410 closed Bug (duplicate)
An empty list is considered as an empty value for JSONField.
Reported by: | Dave White | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 3.1 |
Severity: | Normal | Keywords: | JSONField |
Cc: | toksvig@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Environment: Django 3.1.5, Python 3.8.7, MariaDB 10.5.6
Expected behavior: I should be able to edit an object that contains a JSONField with default=list without having any validation errors if I save without changing the JSONField.
Steps to reproduce:
- Define a field in an Object using models.JSONField(default=list).
- Create a new Object.
- Go to edit view of that Object in Django Admin. You will see the default [] empty list in the JSONField. Don’t change any field.
- Click Save; without having changed anything, you’ll receive a validation error that “This field is required”
- Workaround: put quotes around the "[]” or replace with any valid JSON object. If you try to put random characters in the field you'll receive a "Enter a valid JSON." validation.
Note: This bug seems similar to #31157 https://groups.google.com/g/django-updates/c/BshBo_jmUTA/m/Lu2ZY9mDCQAJ
Cheers,
Dave White
Change History (2)
comment:1 by , 4 years ago
Component: | contrib.admin → Forms |
---|---|
Summary: | JSONField(default=list) causes validation error in Django Admin when populated with default [] value → An empty list is considered as an empty value for JSONField. |
UI/UX: | unset |
comment:2 by , 4 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
This is not related with #31157. An empty list is an empty value for
JSONField
.Duplicate of #26391. Feel-free to add a comment to the original ticket.