Django

Code

Ticket #7992 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

UnicodeDecodeError in newforms-admin

Reported by: Uninen Assigned to: mtredinnick
Milestone: Component: django.contrib.admin
Version: SVN Keywords: admin, unicode
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Im getting following error from a model admin that I just converted from oldforms admin to newforms:

Traceback (most recent call last):

 File "/home/unessanet/django/django/core/handlers/base.py", line 85, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File "/home/unessanet/django/django/contrib/admin/sites.py", line 144, in root
   return self.model_page(request, *url.split('/', 2))

 File "/home/unessanet/django/django/views/decorators/cache.py", line 44, in _wrapped_view_func
   response = view_func(request, *args, **kwargs)

 File "/home/unessanet/django/django/contrib/admin/sites.py", line 161, in model_page
   return admin_obj(request, rest_of_url)

 File "/home/unessanet/django/django/contrib/admin/options.py", line 252, in __call__
   return self.change_view(request, unquote(url))

 File "/home/unessanet/django/django/contrib/admin/options.py", line 570, in change_view
   'title': _('Change %s') % opts.verbose_name,

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128)

The object in question has a proper __unicode__-method and a title with a unicode (non-ascii) character in it. The old admin worked just fine.

I'm running newest trunk (r8114) with MySQL, Apache and mod_python.

Attachments

Change History

07/27/08 14:51:02 changed by Uninen

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

The problem is not in the model (database) data but the Meta-data. I have a verbose_name on the model which is not explicitly set as unicode, which triggers the problem. This did work with the old admin, but does not with the new. Should it work now or should verbose_name and verbose_name_plural be explicitly set as unicode strings in model definition?

07/27/08 15:02:38 changed by mtredinnick

Are you running python 2.3, by any chance?

07/27/08 16:11:59 changed by Uninen

No, python 2.5

But tested it on another machine and the error and solutions are the same: when I change the models Meta-attribute verbose_name from 'Foo Ää' to u'Foo Ää' it works with the newforms-admin. Both work with old admin.

07/28/08 14:41:29 changed by anonymous

Some for me on python 2.4

07/29/08 08:22:09 changed by Karen Tracey <kmtracey@gmail.com>

#8016 is a dup with a patch to django/contrib/admin/options.py that wraps references to verbose_name in force_unicode. Looks like this code perhaps didn't get properly unicodified when unicode support was merged from trunk to newforms-admin, probably because the code was new or moved from another file. A quick check of the pre-newforms-admin trunk code looks like the references to verbose_name were wrapped in force_unicode there.

07/29/08 14:06:07 changed by mtredinnick

  • owner changed from nobody to mtredinnick.

07/29/08 19:35:00 changed by mtredinnick

  • stage changed from Unreviewed to Accepted.

The patch in #8016 looks pretty much correct. You can't substitute UTF-8 bytestrings containing non-ASCII characters (which are valid in verbose_name) into unicode strings (which are returned from ugettext()).

07/29/08 19:52:01 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [8144]) Fixed #7992 -- Interpolate UTF-8 verbose_names correctly into unicode strings in the admin interface. Patch from aabele. Refs #8016.

07/29/08 19:56:29 changed by mtredinnick

By the way, I tried very quickly to write a test for this by adding a non-ASCII, UTF-8 encoded verbose_name to one of the models in regressiontests/admin_views/models.py and it killed the test framework due to what is arguably a bug there. I did test this commit manually, though, and it failed before the patch as indicated in the report, and worked afterwards.

I need to debug the test framework problem and fix that before doing the next bit.

07/30/08 17:59:02 changed by john_scott

Hey Malcolm, is there a separate ticket for the test framework bug? I don't want to hijack a closed ticket, but when doing something simple in my TestCase like self.assertContains(response, u'') I'm getting a UnicodeDecodeError. So if there is a separate ticket I should keep an eye on let me know. Thanks!

(follow-up: ↓ 12 ) 07/30/08 18:05:46 changed by mtredinnick

@john_scott: no, I never got around to opening one because I didn't have a small test case to demonstrate it yet. Feel free to make one if you like.

(in reply to: ↑ 11 ) 08/01/08 10:12:39 changed by john_scott

Replying to mtredinnick:

@john_scott: no, I never got around to opening one because I didn't have a small test case to demonstrate it yet. Feel free to make one if you like.

After much investigating, I believe my issue is unrelated. I'll have to hit django-users to have someone straighten me out.


Add/Change #7992 (UnicodeDecodeError in newforms-admin)




Change Properties
Action