#25949: JSONField with older psycopg2 versions
-------------------------------+--------------------
Reporter: kevcampb | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
When using Django 1.9 with psycopg2==2.5.2 and JSONField for postgres, the
field will be correctly stored as jsonb in the postgres database, but will
be converted to a string when read back.
{{{#!python
from django.contrib.postgres.fields import JSONField
class TestModel(models.Model):
data = JSONField(null=True)
}}}
{{{#!python
tm = TestModel(data=[1,2,3])
tm.save()
}}}
{{{#!sql
select * from bugtest_testmodel
id | data
----+-----------
1 | [1, 2, 3]
}}}
{{{#!sql
select data->0 from bugtest_testmodel;
?column?
----------
1
}}}
{{{#!python
tm = TestModel.objects.all()[0]
tm.data
'[1, 2, 3]'
}}}
The issue is resolved in the latest psycopg2 version (2.6.1). It's
somewhat debatable if this is a bug, but as the behaviour does not match
the Django manual I think it would be best to raise a Warning when using
JSONField with older versions of psycopg2.
--
Ticket URL: <https://code.djangoproject.com/ticket/25949>
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/051.bd4160149e3336ca326349638a5a07c6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.