Opened 9 years ago

Closed 9 years ago

#4472 closed (fixed)

[unicode] Cannot coerce AnonymousUser to unicode

Reported by: sacre@… Owned by: mtredinnick
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: UI/UX:

Description (last modified by mtredinnick)

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@… 9 years ago.

Download all attachments as: .zip

Change History (3)

Changed 9 years ago by sacre@…

comment:1 Changed 9 years ago by mtredinnick

  • Description modified (diff)
  • Keywords [unicode-branch] removed
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from adrian to mtredinnick
  • Patch needs improvement unset

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 Changed 9 years ago by mtredinnick

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

(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