strange validator behaviour

6 views
Skip to first unread message

Daniel Fetchinson

unread,
Jan 10, 2008, 3:58:38 AM1/10/08
to turbo...@googlegroups.com
I swear these are exact copy-and-pastes:

------------------------------------------------------------------------------------------------------------

Python 2.5.1 (r251:54863, Oct 30 2007, 13:45:26)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import turbogears
>>> turbogears.validators.Int( ).to_python('5')
5
>>> turbogears.validators.Int( ).to_python('x')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/FormEncode-0.7.1-py2.5.egg/formencode/api.py",
line 368, in to_python
value = tp(value, state)
File "/usr/lib/python2.5/site-packages/FormEncode-0.7.1-py2.5.egg/formencode/validators.py",
line 924, in _to_python
raise Invalid(self.message('integer', state),
File "/usr/lib/python2.5/site-packages/FormEncode-0.7.1-py2.5.egg/formencode/api.py",
line 194, in message
return trans(self._messages[msgName], **self.gettextargs) % kw
TypeError: ugettext() got an unexpected keyword argument 'domain'
>>>

----------------------------------------------------------------------------------------------------------

Python 2.5.1 (r251:54863, Oct 30 2007, 13:45:26)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import turbogears
>>> turbogears.validators.Int( ).to_python('x')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/FormEncode-0.7.1-py2.5.egg/formencode/api.py",
line 368, in to_python
value = tp(value, state)
File "/usr/lib/python2.5/site-packages/FormEncode-0.7.1-py2.5.egg/formencode/validators.py",
line 925, in _to_python
value, state)
formencode.api.Invalid: Please enter an integer value
>>>

-----------------------------------------------------------------------------------------------------------

As you can see the second session worked as expected but the first one
-- which only differs from the second one by doing first a validation
that goes through -- is totally weird. Can anyone explain?

Cheers,
Daniel

Daniel Fetchinson

unread,
Jan 10, 2008, 4:00:57 AM1/10/08
to turbo...@googlegroups.com
Oh, I forgot to say that my tg version is 1.0.3.2 and formencode 0.7.1

Christoph Zwerschke

unread,
Jan 10, 2008, 5:10:53 AM1/10/08
to turbo...@googlegroups.com
Daniel Fetchinson wrote:
> Oh, I forgot to say that my tg version is 1.0.3.2 and formencode 0.7.1

I recently had some formencode problems as well, and upgrading to
formencode 0.9 helped.

-- Chris

Daniel Fetchinson

unread,
Jan 10, 2008, 2:36:32 PM1/10/08
to turbo...@googlegroups.com
> > Oh, I forgot to say that my tg version is 1.0.3.2 and formencode 0.7.1
>
> I recently had some formencode problems as well, and upgrading to
> formencode 0.9 helped.

Upgraded to 0.9 and the same issue remains. It's very misterious,
appears to be some memory effect there since the only difference
between the two calling sequences is that in one case there was a call
before the problematic one and in the other not.

BTW can anyone reproduce it?

Christoph Zwerschke

unread,
Jan 10, 2008, 2:51:08 PM1/10/08
to turbo...@googlegroups.com

Just tried it on Windows and got the same effect. It happens only if you
run the commands in the shell, not if you run them as a script.

-- Chris

Christoph Zwerschke

unread,
Jan 10, 2008, 3:42:04 PM1/10/08
to turbo...@googlegroups.com

Seems to have something to do with the obscure trickery of translating
messages in FormEncode and TurboGears. There is a special version of
gettext in Turbogears that can handle an additional domain parameter.
FormEncode and TurboGears switch between the gettext versions. The
Validator class has a class attribute dictionary gettextargs which is
used as a parameter for gettext. If the standard version of gettext is
called with that parameter, it throws that exception.

-- Chris

Daniel Fetchinson

unread,
Jan 10, 2008, 4:17:30 PM1/10/08
to turbo...@googlegroups.com

Opened a new ticket on this: http://trac.turbogears.org/ticket/1671

Reply all
Reply to author
Forward
0 new messages