#2269: Unicode error when a TableForm TextField gets a non-ascii value
----------------------------------------------------+-----------------------
Reporter: chrisz | Owner:
Type: defect | Status: new
Priority: high | Milestone: 2.0rc1
Component: TurboGears | Version: 2.0b7
Severity: major | Resolution:
Keywords: tw.forms formencode UnicodeDecodeError |
----------------------------------------------------+-----------------------
Changes (by chrisz):
* keywords: tw.forms UnicodeDecodeError => tw.forms formencode
UnicodeDecodeError
* priority: highest => high
* severity: blocker => major
Old description:
> Here is how to reproduce the bug with TG2.0b7:
>
> Quickstart a new TG2.0b7 project with:
> {{{
> paster quickstart -a foo
> cd foo
> }}}
> In foo/websetup.py, change u'manage' to u'mänäge' (something that is not
> pure ascii), and create the database:
> {{{
> paster setup-app development.ini
> }}}
> In foo/controllers/root.py add the following at the top:
> {{{
> from formencode import validators
> from tw import forms
> from foo.model import DBSession, Permission
>
> test_form = forms.TableForm('test_form',
> fields = [
> forms.TextField('permission_name',
> validator=validators.UnicodeString)
> ])
> }}}
> In the same file, change the index method of the !RootController:
> {{{
> @expose('foo.templates.index')
> def index(self):
> """Handle the front-page."""
> return dict(page='index', form=test_form,
> value=DBSession.query(Permission).one())
> }}}
> In foo/templates/index.html, add the following somewhere in the body:
> {{{
> <div py:replace="form(value)"/>
> }}}
> Run the application:
> {{{
> paster serve development.ini
> }}}
> Surf to http://localhost:8080. You will get the following error:
> {{{
> Module genshi.template.base:516 in _eval
> >> new_attrs.append((name, u''.join(value)))
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1:
> ordinal not in range(128)
> }}}
> It seems that Genshi has a problem displaying the non-ascii value
> 'mänäge' in the text field. I guess this is because of the nested
> rendering (first as a field, then as a form) which converts the value to
> utf-8 in the first pass, while the second pass expects unicode.
>
> This is the absolute base functionality of TurboGears that should really
> work, so I consider this a blocker.
New description:
I had originally posted this as a TG2.0b7 issue, but after some more
analysis it now seems to be a pure tw.forms + formencode issue. The
following code gives a !UnicodeDecodeError:
{{{
from formencode import validators
from tw import forms
field = forms.TextField('test', validator=validators.UnicodeString)
print field.display(u'käse')
}}}
Anyway, this makes using forms with TG2 a real problem for me.
--
Ticket URL: <http://trac.turbogears.org/ticket/2269#comment:1>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "TurboGears Tickets" group.
This group is read-only. No posting by normal members allowed.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears-tickets?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---