Opened 17 years ago

Closed 17 years ago

#4472 closed (fixed)

[unicode] Cannot coerce AnonymousUser to unicode

Reported by: sacre@… Owned by: Malcolm Tredinnick
Component: Contrib apps Version: other branch
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Malcolm Tredinnick)

smart_unicode and force_unciode throw TypeError exception when calling on instance of AnonymousUser. I got this error when trying something like this ( for model Articles.authors = ManyToManyField(User) ):

from django.contrib.auth import AnonyousUser
auser = AnonymousUser()
Article.objects.filter( authors__in = [auser] )

Then i got:

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

Full trackback is in attachment.

Attachments (1)

proxy_unicode_error.txt (780 bytes ) - added by sacre@… 17 years ago.

Download all attachments as: .zip

Change History (3)

by sacre@…, 17 years ago

Attachment: proxy_unicode_error.txt added

comment:1 by Malcolm Tredinnick, 17 years ago

Description: modified (diff)
Keywords: [unicode-branch] removed
Owner: changed from Adrian Holovaty to Malcolm Tredinnick

True. This is kind of obvious in retrospect. The __unicode__ method must return a unicode object, not anything else, so we cannot return lazy translation objects from those methods. Easy enough to fix; painful to track down if we're making the same error anywhere else, though.

comment:2 by Malcolm Tredinnick, 17 years ago

Resolution: fixed
Status: newclosed

(In [5421]) unicode: Fixed #4472 -- Must return unicode objects from unicode methods.
Lazy translation proxies are not an acceptable substitute.

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