#10571: FakePayload Truncates Unicode Content
-------------------------------------+-------------------------------------
               Reporter:  rwagner@…  |          Owner:  nobody
                   Type:             |         Status:  reopened
  Uncategorized                      |      Component:  Testing framework
              Milestone:  1.1        |       Severity:  Normal
                Version:  SVN        |       Keywords:
             Resolution:             |      Has patch:  1
           Triage Stage:  Accepted   |    Needs tests:  0
    Needs documentation:  0          |  Easy pickings:  0
Patch needs improvement:  0          |
-------------------------------------+-------------------------------------
Changes (by droberts@…):

 * easy:   => 0


Comment:

 I just encountered this same problem (Django 1.2.3), but it looks like
 it's still not fully solved in Django 1.3 from the above comment. It seems
 like the real problem here is that FakePayload only works when the content
 is a str and not when it's unicode, and yet it doesn't advertise this
 correctly. If it's passed a unicode, it happily accepts it, failing later
 when .read() is called. This seems like a classic duck-typing bug, but
 since it's very common to expect that functions will accept either str or
 unicode, it seems like the correct behavior here would be to fail hard
 when FakePayload.__init__ is passed a unicode object.

 In my particular case, I was using a StringIO as a the file-like object.
 StringIO.read() returns a str if it's been given strings and unicode if
 it's been given unicode. I seeded it with what to me looked like a string
 but turned out to be a unicode, and no one along the way checked to see
 that the output of f.read() (where f is the StringIO object) was returning
 unicode. A simple check in FakePayload would have saved me a couple of
 hours of debugging what seemed like very mysterious behavior.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/10571#comment:14>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to