Opened 9 years ago

Closed 9 years ago

#4803 closed (invalid)

Don't return translations in __str__ methods

Reported by: smurf@… Owned by: Malcolm Tredinnick
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).

Change History (3)

comment:1 Changed 9 years ago by anonymous

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

comment:2 Changed 9 years ago by smurf@…

Component: UncategorizedInternationalization
Has patch: set
Owner: changed from Jacob to Malcolm Tredinnick

comment:3 Changed 9 years ago by Malcolm Tredinnick

Resolution: invalid
Status: newclosed

This was fixed in trunk in [5590].

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