#28161: contrib.postgres: ArrayField(CITextField) returns string instead of list
--------------------------------------------+------------------------
Reporter: Hendrik Richter | Owner: (none)
Type: Uncategorized | Status: new
Component: contrib.postgres | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/28161>
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/048.096b8b091b175b2a01c5eae58cdb84ad%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.