#27183: JSONField improperly escaped in admin interface during normal usage
----------------------------------+--------------------------------------
Reporter: Jeff Cook | Owner: nobody
Type: Bug | Status: new
Component: contrib.postgres | Version: 1.10
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by ErikW):
* status: closed => new
* resolution: needsinfo =>
Comment:
I too have been impacted by this bug. I'm not using either Mezzanine or
django admin.
I have the field declared on my like like so:
from django.contrib.postgres.fields import JSONField
class FeedStatus(models.Model)
data = JSONField(default=dict)
When I try to access `feed_status.data` -- it returns JSON as a string (ie
"{}" instead of {}}. Each time the object is saved, the empty string is
re-serialized (ie '"\\"{}\\""').
```
In 18:44:50 [30]: f = FeedStatus.objects.get(pk=25806)
In 18:44:54 [31]: f.data = {}
In 18:44:56 [32]: f.save()
In 18:44:59 [33]: f = FeedStatus.objects.get(pk=25806)
In 18:45:01 [34]: f.data
Out 18:45:01 [34]: '{}'
In 18:45:03 [35]: f.save()
In 18:45:05 [36]: f = FeedStatus.objects.get(pk=25806)
In 18:45:07 [37]: f.data
Out 18:45:07 [37]: '"{}"'
In 18:45:10 [38]: f.save()
In 18:45:11 [39]: f = FeedStatus.objects.get(pk=25806)
In 18:45:16 [40]: f.data
Out 18:45:16 [40]: '"\\"{}\\""'
In 18:45:19 [41]: f.save()
In 18:45:20 [42]: f = FeedStatus.objects.get(pk=25806)
In 18:45:23 [43]: f.data
Out 18:45:23 [43]: '"\\"\\\\\\"{}\\\\\\"\\""'
```
This of course leads to incredibly bloated columns in the database (I've
found some that are 10's of MB in size when they should just be a blank
dict!!!)
I'm on Django 1.10.7.
--
Ticket URL: <https://code.djangoproject.com/ticket/27183#comment:6>
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/064.26b64be74023f9f94cd8e262cca5ca9d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.