--
Ticket URL: <https://code.djangoproject.com/ticket/26391>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* 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>
* 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>
* status: new => closed
* resolution: => needsinfo
--
Ticket URL: <https://code.djangoproject.com/ticket/26391#comment:3>
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>
* Attachment "invalid_empty_json_field.png" added.
Comment (by Tim Graham):
That's discussed in #27697.
--
Ticket URL: <https://code.djangoproject.com/ticket/26391#comment:5>
Comment (by Matt Hegarty):
ok - thanks Tim
--
Ticket URL: <https://code.djangoproject.com/ticket/26391#comment:6>