[Django] #32410: JSONField(default=list) causes validation error in Django Admin when populated with default [] value

696 views
Skip to first unread message

Django

unread,
Feb 2, 2021, 3:01:12 PM2/2/21
to django-...@googlegroups.com
#32410: JSONField(default=list) causes validation error in Django Admin when
populated with default [] value
-----------------------------------------+---------------------------
Reporter: eldavo | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.1
Severity: Normal | Keywords: JSONField
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 1 |
-----------------------------------------+---------------------------
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:
1. Define a field in an Object using models.JSONField(default=list).
2. Create a new Object.
3. 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.
4. Click Save; without having changed anything, you’ll receive a
validation error that “This field is required”
5. 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

--
Ticket URL: <https://code.djangoproject.com/ticket/32410>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 2, 2021, 3:30:21 PM2/2/21
to django-...@googlegroups.com
#32410: An empty list is considered as an empty value for JSONField.
----------------------------+--------------------------------------
Reporter: Dave White | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 3.1
Severity: Normal | Resolution:

Keywords: JSONField | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* ui_ux: 1 => 0
* component: contrib.admin => Forms


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/32410#comment:1>

Django

unread,
Feb 2, 2021, 3:38:46 PM2/2/21
to django-...@googlegroups.com
#32410: An empty list is considered as an empty value for JSONField.
----------------------------+--------------------------------------
Reporter: Dave White | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 3.1
Severity: Normal | Resolution: duplicate

Keywords: JSONField | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => duplicate


--
Ticket URL: <https://code.djangoproject.com/ticket/32410#comment:2>

Reply all
Reply to author
Forward
0 new messages