﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20007	psycopg2 should convert SQL arrays into python unicode-arrays	hogbait@…	EricBoersma	"Both test cases should succeed. However, the second one fails, because the cursor returns a utf-8 encoded string array instead of a unicode array.


{{{
#!/usr/bin/env python
# coding=utf8

from django.test import TestCase
#Assuming that the default connection uses psycopg2
from django.db import connection

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])

}}}


The django currently configures psycopg2 to convert strings to strings, but is not configured to convert string arrays into unicode arrays. A potential fix is described here: [https://github.com/django/django/pull/189]

However, you should probably put the change in the cursor constructor as described here: [https://github.com/django/django/commit/6595ee896a9e3bf9cc1a9bd34af0e13bd32d8a3b]

Psycopg2 documentation: [http://initd.org/psycopg/docs/extensions.html#psycopg2.extensions.UNICODEARRAY]"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed	psycopg2 unicode python2		Accepted	1	0	0	1	1	0
