#34435: JSONField with string default raises fields.E010 warning.
--------------------------------------+------------------------------------
Reporter: Tobias Krönke | Owner: stimver
Type: Bug | Status: assigned
Component: Core (System checks) | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by stimver):
what changes should be done , if someone could suggest.
As the warning suggests- that the default value for the JSONField should
be a callable function, rather than an instance, to avoid sharing the
default value between all instances of the field. In the provided code,
the default value is set to an empty string '', which is an instance of a
string and therefore mutable.
To fix the warning, you can change the default value to a callable
function that returns an empty dictionary, like this:
'' message = models.JSONField(editable=False, default=dict)'' .This
ensures that a new empty dictionary is created each time a new instance of
the JSONField is created.
--
Ticket URL: <https://code.djangoproject.com/ticket/34435#comment:3>
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/010701878db4b556-0a01352d-76c8-4e3d-9e70-946c3dbc5a96-000000%40eu-central-1.amazonses.com.