summaryrefslogtreecommitdiff
path: root/django/contrib/postgres/signals.py
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2017-05-03 01:25:30 -0400
committerSimon Charette <charette.s@gmail.com>2017-05-04 00:02:14 -0400
commitb91868507af08234a30e9a8e7c90b37c561ba315 (patch)
tree332ff103ffcc30c800ffa5df968113b32acd9447 /django/contrib/postgres/signals.py
parentf37467ec7a970e3cb9f9f25c370c4072fc994a6e (diff)
downloaddjango-b91868507af08234a30e9a8e7c90b37c561ba315.tar.gz
Fixed #28161 -- Fixed return type of ArrayField(CITextField()).
Thanks Tim for the review.
Diffstat (limited to 'django/contrib/postgres/signals.py')
-rw-r--r--django/contrib/postgres/signals.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/django/contrib/postgres/signals.py b/django/contrib/postgres/signals.py
index 682627de1d..4ffc90c213 100644
--- a/django/contrib/postgres/signals.py
+++ b/django/contrib/postgres/signals.py
@@ -1,8 +1,9 @@
+import psycopg2
from psycopg2 import ProgrammingError
from psycopg2.extras import register_hstore
-def register_hstore_handler(connection, **kwargs):
+def register_type_handlers(connection, **kwargs):
if connection.vendor != 'postgresql':
return
@@ -18,3 +19,17 @@ def register_hstore_handler(connection, **kwargs):
# This is also needed in order to create the connection in order to
# install the hstore extension.
pass
+
+ try:
+ with connection.cursor() as cursor:
+ # Retrieve oids of citext arrays.
+ cursor.execute("SELECT typarray FROM pg_type WHERE typname = 'citext'")
+ oids = tuple(row[0] for row in cursor)
+ array_type = psycopg2.extensions.new_array_type(oids, 'citext[]', psycopg2.STRING)
+ psycopg2.extensions.register_type(array_type, None)
+ except ProgrammingError:
+ # citext is not available on the database.
+ #
+ # The same comments in the except block of the above call to
+ # register_hstore() also apply here.
+ pass