[Django] #20007: psycopg2 should convert SQL arrays into python unicode-arrays

13 views
Skip to first unread message

Django

unread,
Mar 8, 2013, 5:43:19 PM3/8/13
to django-...@googlegroups.com
#20007: psycopg2 should convert SQL arrays into python unicode-arrays
-------------------------------------+-------------------------------------
Reporter: hogbait@… | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.5
(models, ORM) | Keywords: psycopg2 unicode
Severity: Normal | python2
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
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]

--
Ticket URL: <https://code.djangoproject.com/ticket/20007>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 8, 2013, 5:59:12 PM3/8/13
to django-...@googlegroups.com
#20007: psycopg2 should convert SQL arrays into python unicode-arrays
-------------------------------------+-------------------------------------
Reporter: hogbait@… | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: psycopg2 unicode | Unreviewed
python2 | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by hogbait):

* needs_better_patch: => 0
* version: 1.5 => master
* needs_tests: => 0
* needs_docs: => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/20007#comment:1>

Django

unread,
Mar 10, 2013, 6:14:19 PM3/10/13
to django-...@googlegroups.com
#20007: psycopg2 should convert SQL arrays into python unicode-arrays
-------------------------------------+-------------------------------------
Reporter: hogbait@… | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: psycopg2 unicode | Needs documentation: 0
python2 | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* stage: Unreviewed => Accepted


Comment:

I'm not familiar with Postgres arrays but this looks reasonnable.

--
Ticket URL: <https://code.djangoproject.com/ticket/20007#comment:2>

Django

unread,
May 18, 2013, 6:05:05 AM5/18/13
to django-...@googlegroups.com
#20007: psycopg2 should convert SQL arrays into python unicode-arrays
-------------------------------------+-------------------------------------
Reporter: hogbait@… | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: psycopg2 unicode | Needs documentation: 0
python2 | Patch needs improvement: 0
Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by areski):

Can you add an example when you will have this issue with the Django ORM?

--
Ticket URL: <https://code.djangoproject.com/ticket/20007#comment:3>

Django

unread,
Jul 12, 2013, 1:14:05 PM7/12/13
to django-...@googlegroups.com
#20007: psycopg2 should convert SQL arrays into python unicode-arrays
-------------------------------------+-------------------------------------
Reporter: hogbait@… | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: psycopg2 unicode | Needs documentation: 0
python2 | Patch needs improvement: 1

Has patch: 1 | UI/UX: 0
Needs tests: 0 |
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by timo):

* needs_better_patch: 0 => 1


Comment:

The test needs to be incorporated into the Django test suite as well.

--
Ticket URL: <https://code.djangoproject.com/ticket/20007#comment:4>

Django

unread,
Sep 6, 2013, 10:39:36 AM9/6/13
to django-...@googlegroups.com
#20007: psycopg2 should convert SQL arrays into python unicode-arrays
-------------------------------------+-------------------------------------
Reporter: hogbait@… | Owner:
Type: Bug | EricBoersma
Component: Database layer | Status: assigned
(models, ORM) | Version: master
Severity: Normal | Resolution:
Keywords: psycopg2 unicode | Triage Stage: Accepted
python2 | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by EricBoersma):

* status: new => assigned
* owner: nobody => EricBoersma


--
Ticket URL: <https://code.djangoproject.com/ticket/20007#comment:5>

Django

unread,
Sep 6, 2013, 8:44:14 PM9/6/13
to django-...@googlegroups.com
#20007: psycopg2 should convert SQL arrays into python unicode-arrays
-------------------------------------+-------------------------------------
Reporter: hogbait@… | Owner:
Type: Bug | EricBoersma
Component: Database layer | Status: closed
(models, ORM) | Version: master
Severity: Normal | Resolution: fixed

Keywords: psycopg2 unicode | Triage Stage: Accepted
python2 | Needs documentation: 0
Has patch: 1 | Patch needs improvement: 1
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"ded40142a92813a8901faa4a6ca398e6679152f6"]:
{{{
#!CommitTicketReference repository=""
revision="ded40142a92813a8901faa4a6ca398e6679152f6"
Fixed #20007 -- Configured psycopg2 to return UnicodeArrays

Thanks hogbait for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20007#comment:6>

Reply all
Reply to author
Forward
0 new messages