diff options
author | Simon Charette <charette.s@gmail.com> | 2017-05-03 01:25:30 -0400 |
---|---|---|
committer | Simon Charette <charette.s@gmail.com> | 2017-05-04 00:02:14 -0400 |
commit | b91868507af08234a30e9a8e7c90b37c561ba315 (patch) | |
tree | 332ff103ffcc30c800ffa5df968113b32acd9447 /django/contrib/postgres/signals.py | |
parent | f37467ec7a970e3cb9f9f25c370c4072fc994a6e (diff) | |
download | django-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.py | 17 |
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 |