Django

Code

Ticket #4472 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

[unicode] Cannot coerce AnonymousUser to unicode

Reported by: sacre@wp.pl Assigned to: mtredinnick
Milestone: Component: Contrib apps
Version: other branch Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

proxy_unicode_error.txt (0.8 kB) - added by sacre@wp.pl on 06/04/07 02:37:50.

Change History

06/04/07 02:37:50 changed by sacre@wp.pl

  • attachment proxy_unicode_error.txt added.

06/04/07 02:48:03 changed by mtredinnick

  • description changed.
  • needs_better_patch changed.
  • needs_tests changed.
  • owner changed from adrian to mtredinnick.
  • keywords deleted.
  • needs_docs changed.

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.

06/04/07 02:48:51 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #4472 ([unicode] Cannot coerce AnonymousUser to unicode)




Change Properties
Action