#29388: JSONField defaults to empty list gets modified
--------------------------------------------+------------------------
Reporter: Ponytech | Owner: (none)
Type: Bug | Status: new
Component: contrib.postgres | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
Consider this simple model :
{{{
from django.db import models
from django.contrib.postgres.fields import JSONField
class Thing(models.Model):
name = models.CharField(max_length=100)
features = JSONField(default=[], blank=True)
}}}
And this code snippet :
{{{
>>> t1 = Thing.objects.create(name="thing 1")
>>> t1.features.append({"f1": 42, "f2": 56})
>>> t1.features
[{'f1': 42, 'f2': 56}]
>>> t1.save()
>>> t2 = Thing.objects.create(name="thing 2")
>>> t2.features
[{'f1': 42, 'f2': 56}]
}}}
I'd expect t2 features to be an empty list.
My guess is the model default fields gets modified somehow.
--
Ticket URL: <https://code.djangoproject.com/ticket/29388>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/050.aec8b27a1ab4b26deb3df9fe8ac9610b%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.