Discussion:
[FE-discuss] Question about chained validators
Andrea Riciputi
2009-04-19 21:26:06 UTC
Permalink
Hi all,
I've noticed that a chained validator with validate_partial_form=True
is called twice. The first time its .validate_partial() method is
called (which in turn calls .validate_python()),
then .validate_python() is called directly.

The problem is that the second time the input has been already
converted and the validators could fails (e.g. if the input string has
been converted into a datetime object).

Probably I haven't understood how to get this kind of validators to
work properly. I usually define them like this:

class Foo(FancyValidator):
validate_partial_form = True
messages = {
'message_key' : u"the message"
}

def validate_partial(self, values, state):
self.validate_python(values, state)

def validate_python(self, values, state):
...actual validating code here...
...raise Invalid in case...

Can anyone explain me why I get this wrong?

TIA,
Andrea
Ian Bicking
2009-04-20 15:51:32 UTC
Permalink
Huh, looking at the code I think there's a bug. I'll look into it.
Post by Andrea Riciputi
Hi all,
I've noticed that a chained validator with validate_partial_form=True
is called twice. The first time its .validate_partial() method is
called (which in turn calls .validate_python()),
then .validate_python() is called directly.
The problem is that the second time the input has been already
converted and the validators could fails (e.g. if the input string has
been converted into a datetime object).
Probably I haven't understood how to get this kind of validators to
validate_partial_form = True
messages = {
'message_key' : u"the message"
}
self.validate_python(values, state)
...actual validating code here...
...raise Invalid in case...
Can anyone explain me why I get this wrong?
TIA,
Andrea
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
FormEncode-discuss mailing list
https://lists.sourceforge.net/lists/listinfo/formencode-discuss
--
Ian Bicking | http://blog.ianbicking.org
Andrea Riciputi
2009-04-20 16:38:48 UTC
Permalink
Thanks Ian, I'll stay tuned.

Cheers,
Andrea
Post by Ian Bicking
Huh, looking at the code I think there's a bug. I'll look into it.
Hi all,
I've noticed that a chained validator with validate_partial_form=True
is called twice. The first time its .validate_partial() method is
called (which in turn calls .validate_python()),
then .validate_python() is called directly.
The problem is that the second time the input has been already
converted and the validators could fails (e.g. if the input string has
been converted into a datetime object).
Probably I haven't understood how to get this kind of validators to
validate_partial_form = True
messages = {
'message_key' : u"the message"
}
self.validate_python(values, state)
...actual validating code here...
...raise Invalid in case...
Can anyone explain me why I get this wrong?
TIA,
Andrea
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
FormEncode-discuss mailing list
https://lists.sourceforge.net/lists/listinfo/formencode-discuss
--
Ian Bicking | http://blog.ianbicking.org
Loading...