From ded40142a92813a8901faa4a6ca398e6679152f6 Mon Sep 17 00:00:00 2001 From: Eric Boersma Date: Fri, 6 Sep 2013 20:43:41 -0400 Subject: [PATCH] Fixed #20007 -- Configured psycopg2 to return UnicodeArrays Thanks hogbait for the report. --- AUTHORS | 1 + .../db/backends/postgresql_psycopg2/base.py | 1 + tests/backends/tests.py | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/AUTHORS b/AUTHORS index 45ca450d37..93e90910d0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -120,6 +120,7 @@ answer newbie questions, and generally made Django that much better: Craig Blaszczyk David Blewett Artem Gnilov + Eric Boersma Matías Bordese Nate Bragg Sean Brant diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index 6e9df8beb2..71ff2811e2 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -31,6 +31,7 @@ DatabaseError = Database.DatabaseError IntegrityError = Database.IntegrityError psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) +psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY) psycopg2.extensions.register_adapter(SafeBytes, psycopg2.extensions.QuotedString) psycopg2.extensions.register_adapter(SafeText, psycopg2.extensions.QuotedString) diff --git a/tests/backends/tests.py b/tests/backends/tests.py index 25df8ea139..94a92c75b9 100644 --- a/tests/backends/tests.py +++ b/tests/backends/tests.py @@ -963,3 +963,23 @@ class BackendUtilTests(TestCase): '0.1') equal('0.1234567890', 12, 0, '0') + +@unittest.skipUnless( + connection.vendor == 'postgresql', + "This test applies only to PostgreSQL") +class UnicodeArrayTestCase(TestCase): + + def select(self, val): + cursor = connection.cursor() + cursor.execute("select %s", (val,)) + return cursor.fetchone()[0] + + def test_select_ascii_array(self): + a = ["awef"] + b = self.select(a) + self.assertEqual(a[0], b[0]) + + def test_select_unicode_array(self): + a = [u"ᄲawef"] + b = self.select(a) + self.assertEqual(a[0], b[0])