summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-08-11 05:23:19 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-08-11 05:23:19 +0000
commit31ba14761e6b06d9ef3a73ffee1f7ef0e4325db4 (patch)
treeaed037c5936405299046aa895e734b199c85699a
parent049212e95079d612b37b6fb9f3fba8616f5f7a7b (diff)
Fixed #5134 -- Return empty strings as Unicode in psycopg1 backend.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5834 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/db/backends/postgresql/base.py2
-rw-r--r--tests/regressiontests/model_regress/models.py6
2 files changed, 7 insertions, 1 deletions
diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py
index d90f0cc225..9d0967fa2b 100644
--- a/django/db/backends/postgresql/base.py
+++ b/django/db/backends/postgresql/base.py
@@ -278,7 +278,7 @@ def typecast_string(s):
"""
Cast all returned strings to unicode strings.
"""
- if not s:
+ if not s and not isinstance(s, str):
return s
return smart_unicode(s)
diff --git a/tests/regressiontests/model_regress/models.py b/tests/regressiontests/model_regress/models.py
index 0fee831212..7aa9e2a7c4 100644
--- a/tests/regressiontests/model_regress/models.py
+++ b/tests/regressiontests/model_regress/models.py
@@ -10,6 +10,7 @@ class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField()
status = models.IntegerField(blank=True, null=True, choices=CHOICES)
+ misc_data = models.CharField(max_length=100, blank=True)
class Meta:
ordering = ('pub_date','headline')
@@ -30,5 +31,10 @@ An empty choice field should return None for the display name.
>>> a.save()
>>> a.get_status_display() is None
True
+
+Empty strings should be returned as Unicode
+>>> a2 = Article.objects.get(pk=a.id)
+>>> a2.misc_data
+u''
"""
}