Opened 6 years ago

Closed 6 years ago

#29473 closed Bug (needsinfo)

Postgres JSONField escaping to infinity on each save

Reported by: Laurynas Riliskis Owned by:
Component: contrib.postgres Version: 2.0
Severity: Normal Keywords: postgress JSONFields
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

postgress JSONFields are escaping to infinity as you can see in the input below. The same behavior is reproduced through the admin interface.

I commented in bug https://code.djangoproject.com/ticket/26110 but not sure if the issue if the same.

import uuid
from django.db import models
from django.contrib.postgres.fields import JSONField

class PublishedConsent(models.Model):
    uuid = models.UUIDField(
            default=uuid.uuid4,
            editable=False)
    json = JSONField()
>>> p = JSONTest.objects.get(instance="4550d7f3a28c4081af5b3ff5ac62ab60")
>>> p.data
'{}'
>>> p.save()
>>> p = JSONTest.objects.get(instance="4550d7f3a28c4081af5b3ff5ac62ab60")
>>> p.data
'"{}"'
>>> p.save()
>>> p = JSONTest.objects.get(instance="4550d7f3a28c4081af5b3ff5ac62ab60")
>>> p.data
'"\\"{}\\""'
>>> p.save()
>>> p = JSONTest.objects.get(instance="4550d7f3a28c4081af5b3ff5ac62ab60")
>>> p.data
'"\\"\\\\\\"{}\\\\\\"\\""'

Change History (2)

comment:1 by Tim Graham, 6 years ago

You are using Django 2.0? I can't reproduce with this test case for tests/postgres_tests/test_json.py:

def test_string(self):
    instance = JSONModel(field='{}')
    instance.save()
    loaded = JSONModel.objects.get()
    self.assertEqual(loaded.field, '{}')
    loaded.save()
    loaded = JSONModel.objects.get()
    self.assertEqual(loaded.field, '{}')

Does that pass for you? Can you provide a failing test for Django's test suite?

comment:2 by Claude Paroz, 6 years ago

Resolution: needsinfo
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top