I could only reproduce this using an app called django-generic-m2m. I've
read the code and there seems to be nothing special that is messing around
with the ORM, so I think it's a django bug.
traceback:
{{{
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-
packages/django/core/handlers/base.py", line 115, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/var/www/site.com/django/products/views.py", line 103, in detail
print elem
File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py",
line 433, in __str__
return force_text(self).encode('utf-8')
File "/usr/local/lib/python2.7/dist-packages/django/utils/encoding.py",
line 115, in force_text
raise DjangoUnicodeDecodeError(s, *e.args)
DjangoUnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position
4: ordinal not in range(128). You passed in <RelatedObject: [Bad Unicode
data]> (<class 'genericm2m.models.RelatedObject'>)
}}}
#-----
model:
{{{
title = models.CharField(max_length=200)
def __unicode__(self):
return self.title
}}}
#----
unicode method of genericm2m:
{{{
https://github.com/coleifer/django-generic-
m2m/blob/master/genericm2m/models.py#L229
}}}
#----
{{{
DB: MySQL
collation: utf8_unicode_ci
}}}
#----
steps to reproduce:
{{{
- pip install django-generic-m2m
- add 'genericm2m', to installed apps
- create 2 models
- from genericm2m.models import RelatedObjectsDescriptor
- add related = RelatedObjectsDescriptor() to one of your models
- add a model instance that returns unicode characters
- model1.related.connect(model2)
- for elem in model1.related.all()
print elem
}}}
----
some guy in irc suggested to upgrade to ".format()"
--
Ticket URL: <https://code.djangoproject.com/ticket/20573>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* needs_docs: => 0
* resolution: => invalid
* needs_tests: => 0
* needs_better_patch: => 0
Comment:
That's a bug in django-generic-m2m `__unicode__` method. It should return
a unicode string, and currently it returns a bytestring.
It should be either `return u'%s related to %s ("%s")' % (self.parent,
self.object, self.alias)` (notice the u prefix) or alternatively the file
could import `from __future__ import unicode_literals`.
--
Ticket URL: <https://code.djangoproject.com/ticket/20573#comment:1>
* status: closed => new
* needs_better_patch: 0 => 1
* component: Database layer (models, ORM) => contrib.admin
* resolution: invalid =>
* needs_tests: 0 => 1
* version: 1.5 => master
* needs_docs: 0 => 1
* has_patch: 0 => 1
* ui_ux: 0 => 1
* type: Bug => Uncategorized
Comment:
1
--
Ticket URL: <https://code.djangoproject.com/ticket/20573#comment:3>
* needs_better_patch: 0 => 1
* component: Database layer (models, ORM) => contrib.admin
* needs_tests: 0 => 1
* version: 1.5 => master
* needs_docs: 0 => 1
* has_patch: 0 => 1
* ui_ux: 0 => 1
* type: Bug => Uncategorized
Comment:
1
--
Ticket URL: <https://code.djangoproject.com/ticket/20573#comment:2>
* needs_better_patch: 0 => 1
* component: Database layer (models, ORM) => contrib.admin
* needs_tests: 0 => 1
* version: 1.5 => master
* needs_docs: 0 => 1
* has_patch: 0 => 1
* ui_ux: 0 => 1
* type: Bug => Uncategorized
Comment:
1
--
Ticket URL: <https://code.djangoproject.com/ticket/20573#comment:4>
Comment (by ogpcludi <sample@…>):
1
--
Ticket URL: <https://code.djangoproject.com/ticket/20573#comment:6>
* status: new => assigned
* owner: nobody => anonymous
Comment:
1
--
Ticket URL: <https://code.djangoproject.com/ticket/20573#comment:5>