Opened 12 years ago

Last modified 12 years ago

#19114 closed Bug

admin LogEntry __unicode__() returns a proxy in some cases — at Initial Version

Reported by: niko@… Owned by: nobody
Component: contrib.admin Version: 1.4
Severity: Normal Keywords: proxy unicode logentry admin
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

the admin LogEntry function unicode() returns a proxy object for lazzy translation string in the case the self.action_flag is different from 1 2 or 3.

This leads to an exception in the admin when trying to delete such LogEntry or an associated object of it, when the admin needs its name to be displayed in the "delete confirmation" page.

the fix is to cast to unicode the returned value in line 46 of
django/contrib/admin/models.py

return unicode(_('LogEntry Object'))

it is because we are using a custom action_flag of 4 in some of our LogEntry, that the bug popped up.
You will notice that the 3 other cases in the unicode function are not problematic because they are printf and therefor a new unicode string is geenrated and returned, and the proxy is "gettext-ed" before.

the exception was:

File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 111, in get_response

response = callback(request, *callback_args, callback_kwargs)

File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/options.py", line 366, in wrapper

return self.admin_site.admin_view(view)(*args, kwargs)

File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py", line 91, in _wrapped_view

response = view_func(request, *args, kwargs)

File "/usr/local/lib/python2.6/dist-packages/django/views/decorators/cache.py", line 89, in _wrapped_view_func

response = view_func(request, *args, kwargs)

File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/sites.py", line 196, in inner

return view(request, *args, kwargs)

File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py", line 25, in _wrapper

return bound_func(*args, kwargs)

File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py", line 91, in _wrapped_view

response = view_func(request, *args, kwargs)

File "/usr/local/lib/python2.6/dist-packages/django/utils/decorators.py", line 21, in bound_func

return func(self, *args2, kwargs2)

File "/usr/local/lib/python2.6/dist-packages/django/db/transaction.py", line 209, in inner

return func(*args, kwargs)

File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/options.py", line 1274, in delete_view

[obj], opts, request.user, self.admin_site, using)

File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/util.py", line 132, in get_deleted_objects

to_delete = collector.nested(format_callback)

File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/util.py", line 186, in nested

roots.extend(self._nested(root, seen, format_callback))

File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/util.py", line 169, in _nested

children.extend(self._nested(child, seen, format_callback))

File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/util.py", line 171, in _nested

ret = [format_callback(obj)]

File "/usr/local/lib/python2.6/dist-packages/django/contrib/admin/util.py", line 130, in format_callback

force_unicode(obj))

File "/usr/local/lib/python2.6/dist-packages/django/utils/encoding.py", line 71, in force_unicode

s = unicode(s)

TypeError: coercing to Unicode: need string or buffer, proxy found

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top