[Django] #26391: JSONField empty_values

6 views
Skip to first unread message

Django

unread,
Mar 21, 2016, 4:33:11 PM3/21/16
to django-...@googlegroups.com
#26391: JSONField empty_values
-------------------------------------+-------------------------------------
Reporter: sim1234 | Owner:
Type: | Status: new
Cleanup/optimization |
Component: contrib.postgres | Version: 1.9
Severity: Normal | Keywords: JSON JSONField postgres
| forms
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
When validating required JSONField with values '{}', '[]' or '""' a
ValidationError is raised.
In case of JSON, only None (null) should be considered an empty value.

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

Django

unread,
Mar 21, 2016, 4:40:36 PM3/21/16
to django-...@googlegroups.com
#26391: JSONField empty_values
-------------------------------------+-------------------------------------
Reporter: sim1234 | Owner:
Type: | Status: new
Cleanup/optimization |
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution:
Keywords: JSON JSONField | Triage Stage:
postgres forms | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by sim1234):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Pull request: [https://github.com/django/django/pull/6320]

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

Django

unread,
Mar 21, 2016, 8:04:22 PM3/21/16
to django-...@googlegroups.com
#26391: JSONField empty_values
-------------------------------------+-------------------------------------
Reporter: sim1234 | Owner:
Type: | Status: new
Cleanup/optimization |
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution:
Keywords: JSON JSONField | Triage Stage:
postgres forms | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* needs_tests: 0 => 1


Comment:

Regression tests are needed to demonstrate what this fixes. Also the
current patch causes a regression of
`postgres_tests.test_json.TestFormField.test_valid_empty`.

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

Django

unread,
Mar 23, 2016, 11:56:18 AM3/23/16
to django-...@googlegroups.com
#26391: JSONField empty_values
-------------------------------------+-------------------------------------
Reporter: sim1234 | Owner:
Type: | Status: closed

Cleanup/optimization |
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution: needsinfo

Keywords: JSON JSONField | Triage Stage:
postgres forms | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

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


--
Ticket URL: <https://code.djangoproject.com/ticket/26391#comment:3>

Django

unread,
Jan 5, 2021, 1:52:28 PM1/5/21
to django-...@googlegroups.com
#26391: JSONField empty_values
-------------------------------------+-------------------------------------
Reporter: sim1234 | Owner: (none)
Type: | Status: closed

Cleanup/optimization |
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution: needsinfo
Keywords: JSON JSONField | Triage Stage:
postgres forms | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Hegarty):

Can we re-open this as a bug? The default behaviour of JSONFields in the
admin console is to fail when you try to save (see attached).
Also raised on [https://stackoverflow.com/a/56271722/39296 SO]

The workaround is:
{{{
# forms.py
class ValidEmptyJSONField(forms.JSONField):
empty_values = [None, "", [], ()]

from django.db.models import JSONField

class ValidEmptyJSONField(JSONField):
"""
Overridden to permit valid empty JSON.
"""
empty_values = [None, "", [], ()]

def formfield(self, **kwargs):
from app import forms
return super().formfield(**{"form_class":
forms.ValidEmptyJSONField, **kwargs})
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26391#comment:4>

Django

unread,
Jan 5, 2021, 1:52:50 PM1/5/21
to django-...@googlegroups.com
#26391: JSONField empty_values
-------------------------------------+-------------------------------------
Reporter: sim1234 | Owner: (none)
Type: | Status: closed

Cleanup/optimization |
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution: needsinfo
Keywords: JSON JSONField | Triage Stage:
postgres forms | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Matt Hegarty):

* Attachment "invalid_empty_json_field.png" added.

Django

unread,
Jan 5, 2021, 6:03:52 PM1/5/21
to django-...@googlegroups.com
#26391: JSONField empty_values
-------------------------------------+-------------------------------------
Reporter: sim1234 | Owner: (none)
Type: | Status: closed

Cleanup/optimization |
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution: needsinfo
Keywords: JSON JSONField | Triage Stage:
postgres forms | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

That's discussed in #27697.

--
Ticket URL: <https://code.djangoproject.com/ticket/26391#comment:5>

Django

unread,
Jan 6, 2021, 5:42:27 AM1/6/21
to django-...@googlegroups.com
#26391: JSONField empty_values
-------------------------------------+-------------------------------------
Reporter: sim1234 | Owner: (none)
Type: | Status: closed

Cleanup/optimization |
Component: contrib.postgres | Version: 1.9
Severity: Normal | Resolution: needsinfo
Keywords: JSON JSONField | Triage Stage:
postgres forms | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Matt Hegarty):

ok - thanks Tim

--
Ticket URL: <https://code.djangoproject.com/ticket/26391#comment:6>

Reply all
Reply to author
Forward
0 new messages