Code

Opened 7 years ago

Closed 7 years ago

#4803 closed (invalid)

Don't return translations in __str__ methods

Reported by: smurf@… Owned by: mtredinnick
Component: Internationalization Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I just saw a rather lengthy chain of errors which ended in a totally untraceable

[Sun Jul 08 15:43:03 2007] [error] [client 192.109.102.35] FastCGI: server "/daten/web/smurf.noris.de/sweb/smurf.fcg" stderr:     new_obj = func(obj, *arg_vals)
[Sun Jul 08 15:43:03 2007] [error] [client 192.109.102.35] FastCGI: server "/daten/web/smurf.noris.de/sweb/smurf.fcg" stderr:   File "/usr/lib/python2.5/site-packages/django/template/defaultfilters.py", line 38, in _dec
[Sun Jul 08 15:43:03 2007] [error] [client 192.109.102.35] FastCGI: server "/daten/web/smurf.noris.de/sweb/smurf.fcg" stderr:     args[0] = smart_string(args[0])
[Sun Jul 08 15:43:03 2007] [error] [client 192.109.102.35] FastCGI: server "/daten/web/smurf.noris.de/sweb/smurf.fcg" stderr:   File"/usr/lib/python2.5/site-packages/django/template/defaultfilters.py", line 27, in smart_string
[Sun Jul 08 15:43:03 2007] [error] [client 192.109.102.35] FastCGI: server "/daten/web/smurf.noris.de/sweb/smurf.fcg" stderr:     obj = str(obj)
[Sun Jul 08 15:43:03 2007] [error] [client 192.109.102.35] FastCGI: server "/daten/web/smurf.noris.de/sweb/smurf.fcg" stderr: TypeError: __str__ returned non-string (type instance)

The problem was fixed by this change:

diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py
index e8384ba..5de8927 100644
--- a/django/contrib/auth/models.py
+++ b/django/contrib/auth/models.py
@@ -282,7 +282,7 @@ class AnonymousUser(object):
         pass
 
     def __str__(self):
-        return _('AnonymousUser')
+        return 'AnonymousUser'
 
     def __eq__(self, other):
         return isinstance(other, self.__class__)

I don't think str methods should be allowed to return translations (or be allowed to fail, for that matter -- much like repr).

Attachments (0)

Change History (3)

comment:1 Changed 7 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Stupid wiki-ization. Of course that's __str__ and __repr__, not str and repr.

comment:2 Changed 7 years ago by smurf@…

  • Component changed from Uncategorized to Internationalization
  • Has patch set
  • Owner changed from jacob to mtredinnick

comment:3 Changed 7 years ago by mtredinnick

  • Resolution set to invalid
  • Status changed from new to closed

This was fixed in trunk in [5590].

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.