Code

Opened 4 years ago

Closed 4 years ago

#14418 closed (wontfix)

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

Reported by: djoume 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:

Description

Hi,

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'))
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?

Attachments (0)

Change History (1)

comment:1 Changed 4 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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 models.py 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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.