Opened 8 years ago

Closed 7 years ago

#14418 closed (wontfix)

lazy instances are not resolved to string when used as Exception value

Reported by: Djoume Salvetti Owned by: nobody
Component: Uncategorized Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:



If in my django application I raise an Exception with a lazy string as value, the django 500 handler won't display the Exception class but will display instead "<django.utils.functional.proxy object at 0x8e10bac>"

Here is what I believe to be the minimal code to reproduce the issue

>>> from django.utils.translation import ugettext, ugettext_lazy
>>> print Exception(ugettext(u'test'))
>>> print Exception(ugettext_lazy(u'test'))
<django.utils.functional.__proxy__ object at 0x88ca4ac>

Should this be considered a bug in django or lazy string are not supported as exception value?

Change History (1)

comment:1 Changed 7 years ago by Russell Keith-Magee

Resolution: wontfix
Status: newclosed

I think this needs to be chalked up to a limitation of ugettext_lazy().

However, as far as I can make out, it shouldn't be a practical limitation in most situations -- exceptions should generally be able to use ugettext, as they will be invoked at runtime. ugettext_lazy only needs to be used when you need to put in a translation that will be interpreted during parsing. The classic example is translations on field names. THe field itself is an attribute of a class, and as such, the call to translate will be made when the file is parsed.

Exceptions are generally raised as a result of runtime behavior; I can't think of an obvious scenario where you need to use ugettext_lazy in an Exception in the way you describe.

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