#14417 closed (invalid)
UnicodeDecodeError exception in recent actions
Reported by: | ctetruite | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 1.2 |
Severity: | Keywords: | unicode | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Here is my situation.
I have a model with this verbose_name in meta data : u"Matériel d'occasion". The thing is this is a non ascii string. I do some stuff on an object of this model. Then, when I go the the admin page, I get this server error :
Caught UnicodeDecodeError while rendering: ('ascii', "Mat\xc3\xa9riel d'occasion", 3, 4, 'ordinal not in range(128)')
It occurs in the template django/contrib/admin/templates/admin/index.html at line 70 :
<span class="mini quiet">{% filter capfirst %}{% trans entry.content_type.name %}{% endfilter %}</span>
Attachments (3)
Change History (12)
by , 14 years ago
comment:1 by , 14 years ago
by , 14 years ago
comment:2 by , 14 years ago
I've just added a test that specifically tests this. But on my system, it passes without your patch.
Why would entry.content_type.name not be an Unicode string in the first place?
The following snippet could indicate you if ContentType names are really all Unicode strings.
from django.contrib.contenttypes.models import ContentType for c in ContentType.objects.all(): print c.name.__class__, c.name
comment:3 by , 14 years ago
So I've learnt how to use the test suite. Here are my results. Adding your unit test, it also passes for me. It outputs that when displaying content types: <type 'unicode'> ¿Chapter?
Then, I changed the Chapter verbose name from '¿Chapter?' to u"Matériel d'occasion" with a french accent. And so on in the unit test. Executing tests give me this:
<type 'unicode'> Matériel d'occasion
But the test fails with this error:
AssertionError: Couldn't find '<span class="mini quiet">Matériel d'occasion</span>' in response
Did I configured models in the wrong way ?
comment:4 by , 14 years ago
That's a totally different error. Simple quotes are converted to ' in the HTML result. So your test case should test for:
self.assertContains(response, """<span class="mini quiet">Matériel d'occasion</span>""")
comment:5 by , 14 years ago
Oops, sorry. No problem with the test suite: sqlite or mysql.
With my application in dev mode, using MySql (DEFAULT CHARACTER SET utf8 COLLATE utf8_bin), I tried accessing admin page. I've just printed content_type class value at the same place that in my patch. I get this:
Development server is running at http://127.0.0.1:8000/ Quit the server with CONTROL-C. <type 'str'> Matériel d'occasion <type 'str'> Matériel d'occasion <type 'str'> Matériel d'occasion [02/Dec/2010 21:15:48] "GET /admin/ HTTP/1.1" 500 394166
Whereas in the test suite it's <unicode>. In the database:
select * from django_content_type; Matériel d'occasion | website | occmaterial | ...
comment:6 by , 14 years ago
I suspect some database configuration problem. Did you try to get the class value of any other CharField on one of your own models?
comment:7 by , 14 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Well, ramiro friendly pointed me to http://docs.djangoproject.com/en/1.2/ref/databases/#collation-settings
It is surely the cause of your problems (using utf8_bin collation).
Stack trace