{{{
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/28161>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Uncategorized => Bug
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
Comment:
We'll have to do
[https://github.com/django/django/blob/d0e43f225f59145903c72c650eeef1f80e12f9ed/django/contrib/postgres/apps.py#L19-L20
the same thing we do for hstore].
Marking as release blocker because it's a bug in a newly introduced
feature.
--
Ticket URL: <https://code.djangoproject.com/ticket/28161#comment:1>
* status: new => assigned
* owner: (none) => Simon Charette
--
Ticket URL: <https://code.djangoproject.com/ticket/28161#comment:2>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/8453 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/28161#comment:3>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/28161#comment:4>
Comment (by Hendrik Richter):
Replying to [comment:3 Simon Charette]:
> [https://github.com/django/django/pull/8453 PR]
Thank you for the quick fix, that helps a lot :-) Awesome!
--
Ticket URL: <https://code.djangoproject.com/ticket/28161#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"b91868507af08234a30e9a8e7c90b37c561ba315" b9186850]:
{{{
#!CommitTicketReference repository=""
revision="b91868507af08234a30e9a8e7c90b37c561ba315"
Fixed #28161 -- Fixed return type of ArrayField(CITextField()).
Thanks Tim for the review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28161#comment:6>
Comment (by Simon Charette <charette.s@…>):
In [changeset:"246166cfe4d5d054fcef452c5af2d0b0e5f37151" 246166cf]:
{{{
#!CommitTicketReference repository=""
revision="246166cfe4d5d054fcef452c5af2d0b0e5f37151"
[1.11.x] Fixed #28161 -- Fixed return type of ArrayField(CITextField()).
Thanks Tim for the review.
Backport of b91868507af08234a30e9a8e7c90b37c561ba315 from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28161#comment:7>
Comment (by Tim Graham <timograham@…>):
In [changeset:"a8b03bea180e0660c0e159f3e7cf6192b512925f" a8b03bea]:
{{{
#!CommitTicketReference repository=""
revision="a8b03bea180e0660c0e159f3e7cf6192b512925f"
Refs #28161 -- Doc'd INSTALLED_APPS requirement for ArrayField(CIText).
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28161#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"953067d8dcb62baba22c0a5f607b5e1d08099f51" 953067d8]:
{{{
#!CommitTicketReference repository=""
revision="953067d8dcb62baba22c0a5f607b5e1d08099f51"
[2.2.x] Refs #28161 -- Doc'd INSTALLED_APPS requirement for
ArrayField(CIText).
Backport of a8b03bea180e0660c0e159f3e7cf6192b512925f from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28161#comment:9>