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
This commit is contained in:
Malcolm Tredinnick 2007-08-11 05:23:19 +00:00
parent 049212e950
commit 31ba14761e
2 changed files with 7 additions and 1 deletions

View File

@ -278,7 +278,7 @@ def typecast_string(s):
""" """
Cast all returned strings to unicode strings. Cast all returned strings to unicode strings.
""" """
if not s: if not s and not isinstance(s, str):
return s return s
return smart_unicode(s) return smart_unicode(s)

View File

@ -10,6 +10,7 @@ class Article(models.Model):
headline = models.CharField(max_length=100, default='Default headline') headline = models.CharField(max_length=100, default='Default headline')
pub_date = models.DateTimeField() pub_date = models.DateTimeField()
status = models.IntegerField(blank=True, null=True, choices=CHOICES) status = models.IntegerField(blank=True, null=True, choices=CHOICES)
misc_data = models.CharField(max_length=100, blank=True)
class Meta: class Meta:
ordering = ('pub_date','headline') ordering = ('pub_date','headline')
@ -30,5 +31,10 @@ An empty choice field should return None for the display name.
>>> a.save() >>> a.save()
>>> a.get_status_display() is None >>> a.get_status_display() is None
True True
Empty strings should be returned as Unicode
>>> a2 = Article.objects.get(pk=a.id)
>>> a2.misc_data
u''
""" """
} }