#28161 closed Bug (fixed)
contrib.postgres: ArrayField(CITextField) returns string instead of list
Reported by: | Hendrik Richter | Owned by: | Simon Charette |
---|---|---|---|
Component: | contrib.postgres | Version: | 1.11 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The following code
from django.db import models from django.contrib.postgres.fields import ArrayField, CITextField class Foo(models.Model): bar = ArrayField(models.TextField) baz = ArrayField(CITextField())
has this wrong behaviour:
x = Foo.objects.get(id=1) x.bar # => ["Foo", "Bar"] x.baz # => "{Foo,Bar}"
This is due to https://github.com/psycopg/psycopg2/issues/268 which requires registering a new adapter for citext fields:
Use
select typarray from pg_type where typname = 'citext';
to get the oid, then do
psycopg2.extensions.register_type( psycopg2.extensions.new_array_type( (the_returned_oid,), 'citext[]', psycopg2.STRING))
for the correct behaviour in plain psycopg2.
Django should do that automatically if any of the CI*Fields is used. Alternatively, the ArrayField should convert the result string manually to the proper list.
Change History (9)
comment:1 by , 8 years ago
Severity: | Normal → Release blocker |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 8 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:4 by , 8 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:5 by , 8 years ago
Note:
See TracTickets
for help on using tickets.
We'll have to do the same thing we do for hstore.
Marking as release blocker because it's a bug in a newly introduced feature.