Non-ASCII description results in UnicodeEncodeError

2 views
Skip to first unread message

Daniel Nouri

unread,
Jul 30, 2010, 10:09:28 AM7/30/10
to ish.io
Rendering the description in ``formish/templates/mako/formish/field/
description.html`` uses this Python code:

filters.html_escape(unicode(field.description))

At this point, ``field.description`` is not of type unicode, but of
type ``RenderableObjectWrapper``. Due to the lack of a
``__unicode__`` method on that class that delegates to
self.__subject__, calling ``unicode(field.description)`` will result
in the equivalent of ``str(field.description.__subject__)``, which
raises ``UnicodeEncodeError`` for any fields that have non-ascii
characters.

To reproduce this error, use a unicode description with non-ascii
characters in any of your form fields' descriptions. A possible
solution would be to include a ``__unicode__`` method on
``RenderableObjectWrapper`` that looks like this:

def __unicode__(self):
return unicode(self.__subject__)


--
Daniel Nouri

Tim Parkin

unread,
Aug 3, 2010, 4:30:19 AM8/3/10
to ish.io
Hi Daniel,

I'll take a look at this and try to get a release out later in the
week if necessary

Thanks for posting this

Tim
Reply all
Reply to author
Forward
0 new messages