#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 , 10 years ago
| Component: | Uncategorized → Documentation |
|---|---|
| Owner: | changed from to |
| Status: | new → assigned |
| Summary: | JSONField with older psycopg2 versions → Document that JSONField requires Psycopg 2.5.4+ |
| Triage Stage: | Unreviewed → Accepted |
| Type: | Uncategorized → Cleanup/optimization |
Note:
See TracTickets
for help on using tickets.
Psycopg 2.5.4 added
jsonbsupport. I think it's probably enough to document this.