Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25949 closed Cleanup/optimization (fixed)

Document that JSONField requires Psycopg 2.5.4+

Reported by: Kevin Campbell Owned by: Tim Graham
Component: Documentation Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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.

from django.contrib.postgres.fields import JSONField
class TestModel(models.Model):
    data = JSONField(null=True)
tm = TestModel(data=[1,2,3])
tm.save()
select * from bugtest_testmodel
 id |   data
----+-----------
  1 | [1, 2, 3]
select data->0 from bugtest_testmodel;
 ?column?
----------
 1
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.

Change History (4)

comment:1 by Tim Graham, 9 years ago

Component: UncategorizedDocumentation
Owner: changed from nobody to Tim Graham
Status: newassigned
Summary: JSONField with older psycopg2 versionsDocument that JSONField requires Psycopg 2.5.4+
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

Psycopg 2.5.4 added jsonb support. I think it's probably enough to document this.

comment:2 by Tim Graham, 9 years ago

Has patch: set

comment:3 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In b26d147:

Fixed #25949 -- Documented Psycopg2 version requirement for JSONField.

comment:4 by Tim Graham <timograham@…>, 9 years ago

In 571f7b75:

[1.9.x] Fixed #25949 -- Documented Psycopg2 version requirement for JSONField.

Backport of b26d147259202455ce356755b729c3dcb16ae9e6 from master

Note: See TracTickets for help on using tickets.
Back to Top