From 0ced9f68f3d8df6d09f538101c8cf94511a199f0 Mon Sep 17 00:00:00 2001 From: Ian Kelly Date: Fri, 13 Mar 2009 19:58:56 +0000 Subject: [PATCH] [1.0.X] Fixed #10238: coerce TextField values to unicode in the oracle backend. Backport of [10049] from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10050 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/oracle/query.py | 4 ++++ tests/regressiontests/datatypes/models.py | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/django/db/backends/oracle/query.py b/django/db/backends/oracle/query.py index de169d6901..1ca32c0c66 100644 --- a/django/db/backends/oracle/query.py +++ b/django/db/backends/oracle/query.py @@ -6,6 +6,7 @@ Derives from: django.db.models.sql.query.Query import datetime from django.db.backends import util +from django.utils.encoding import force_unicode # Cache. Maps default query class to new Oracle query class. _classes = {} @@ -57,6 +58,9 @@ def query_class(QueryClass, Database): TimeField, BooleanField, NullBooleanField, DecimalField, Field if isinstance(value, Database.LOB): value = value.read() + if field and field.get_internal_type() == 'TextField': + value = force_unicode(value) + # Oracle stores empty strings as null. We need to undo this in # order to adhere to the Django convention of using the empty # string instead of null, but only if the field accepts the diff --git a/tests/regressiontests/datatypes/models.py b/tests/regressiontests/datatypes/models.py index 7e76d6a669..0ad809a45d 100644 --- a/tests/regressiontests/datatypes/models.py +++ b/tests/regressiontests/datatypes/models.py @@ -13,6 +13,7 @@ class Donut(models.Model): baked_date = models.DateField(null=True) baked_time = models.TimeField(null=True) consumed_at = models.DateTimeField(null=True) + review = models.TextField() class Meta: ordering = ('consumed_at',) @@ -82,6 +83,12 @@ datetime.datetime(2007, 4, 20, 16, 19, 59) >>> Donut.objects.filter(consumed_at__year=2008) [] +# Regression test for #10238: TextField values returned from the database +# should be unicode. +>>> d2 = Donut.objects.create(name=u'Jelly Donut', review=u'Outstanding') +>>> Donut.objects.get(id=d2.id).review +u'Outstanding' + """} # Regression test for #8354: the MySQL backend should raise an error if given