Unwarranted UnicodeDecodeErrors in tw2 form - Desperately seeking help!

24 views
Skip to first unread message

Moritz Schlarb

unread,
Jun 6, 2012, 3:20:27 AM6/6/12
to TurboGears, mako-d...@googlegroups.com, sp...@googlegroups.com, toscawidge...@googlegroups.com
Dear all,

I got some mysterious Unicode-and-Charsets-related problem in my
application for which I can't find the cause. Sorry to spam all 4 groups
with thi... I hope someone can bump me to the right direction:

I'm using tgext.crud and sprox with tw2 to generate my Administration
interface (most of the related code is in this file:
https://github.com/moschlar/SAUCE/blob/master/sauce/controllers/crc.py).

Now there was a small bug in the value getter from sprox that caused
SingleSelectFields option lists to be only str and not unicode objects,
but Alessandro fixed that already.

Now the next problem arises from a plain TextField (ignore all things
related to Bootstrap, I checked that using the standard tw2.forms
widgets doesn't change the issue :( ).

The field has the id "name" and is a Column(Unicode()) in SQLAlchemy.

Uploading the traceback to PylonsHQ doesn't work atm, so I made some
screenshots :-/:
Old design with tw1, works fine:
http://fox.moritz-schlarb.de:8080/files/old_design.png
The listing page, works fine:
http://fox.moritz-schlarb.de:8080/files/listing.png
If I click edit - traceback in text form:
http://fox.moritz-schlarb.de:8080/files/traceback.txt
Traceback as screenshot, highlighted the frame where the type of the
value diverts: http://fox.moritz-schlarb.de:8080/files/Server%20Error2.png

I already tried some things: I changed the templating code in tw2.core
to explicitly use render_unicode in mako, you see that in the traceback,
but that changed nothing. As mentioned, I tried using the plain
tw2.forms widgets, but that changed nothing either.

If anyone has a clue, please, please tell me! ;)

I'd be glad to provide any additional information that could be helpful!
I'd even let you play around with the web traceback if that helps...

Hopeful cheers,

Moritz

Alessandro Molina

unread,
Jun 6, 2012, 4:48:41 AM6/6/12
to TurboGears
The issue was related to UnicodeString validator.
It seems that tw2 forms expect an unicode string when rendering values
while tw1 forms expected an encoded string.

Default behavior of the UnicodeString validator is to convert value to
unicode when receiving it from the web (on form submission) and
convert it back to a utf-8 encoded string when having to send it back
to the browser. While this usually makes sense it breaks TW2.

The latest commit on sprox should fix your issue as it tells to the
validator to avoid encoding back the string when sending it out, this
makes the tw2 field receive an unicode instance and work as expected.
> --
> You received this message because you are subscribed to the Google Groups "sprox" group.
> To post to this group, send email to sp...@googlegroups.com.
> To unsubscribe from this group, send email to sprox+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sprox?hl=en.
>

Moritz Schlarb

unread,
Jun 6, 2012, 7:13:07 AM6/6/12
to turbo...@googlegroups.com
That did it!

Thank you so much, Alessandro!

> To unsubscribe from this group, send email to sprox+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages