CompoundFormField widget and validation

5 views
Skip to first unread message

Patrick Lewis

unread,
Nov 23, 2007, 10:41:36 AM11/23/07
to TurboGears
Hi, I'm having some trouble with validating a CompoundFormField, and
I'm not sure how to proceed. As an example of my problem, take this
controller:

http://paste.turbogears.org/paste/1776

This url succeeds (with validation):
http://localhost:8080/save?mywidget.hidden=1&mywidget.number=2

and these fail validation (as they should), redirecting back to index
http://localhost:8080/save?mywidget.hidden=1&mywidget.number=foo
http://localhost:8080/save?mywidget.hidden=&mywidget.number=2
http://localhost:8080/save?mywidget.number=2

But this url doesn't fail at all, and goes straight to the save
method, apparently bypassing validation.

http://localhost:8080/save

Any thoughts as to what's going on here?

Diez B. Roggisch

unread,
Nov 23, 2007, 11:19:12 AM11/23/07
to turbo...@googlegroups.com
Patrick Lewis schrieb:

Maybe trying to set tg_errors=None as explicit method parameter helps -
I _think_ it should be part of the signature, but ATM that's just a guess.

Diez

Patrick Lewis

unread,
Nov 23, 2007, 11:54:36 AM11/23/07
to TurboGears
I just tried that, and it doesn't seem to make a difference.

Glauco

unread,
Nov 27, 2007, 4:16:54 AM11/27/07
to turbo...@googlegroups.com
Patrick Lewis ha scritto:

why you do this with a compound? is only an example i hope.

i cannot see the error.
any way if i'm not wrong the problem is validation system,
i'm not sure the CompoundWidget can use validation in this manner...


Glauco


--
+------------------------------------------------------------+
Glauco Uri
glauco(at)sferacarta.com

Sfera Carta SoftwareĊ½ info(at)sferacarta.com
Via Bazzanese,69 Casalecchio di Reno(BO) - Tel. 051591054
+------------------------------------------------------------+


Patrick Lewis

unread,
Nov 27, 2007, 9:58:21 AM11/27/07
to TurboGears


On Nov 27, 4:16 am, Glauco <gla...@sferacarta.com> wrote:
> Patrick Lewis ha scritto:
> > Hi, I'm having some trouble with validating a CompoundFormField, and
> > I'm not sure how to proceed. As an example of my problem, take this
> > controller:
>
> >http://paste.turbogears.org/paste/1776
>
> > This url succeeds (with validation):
> >http://localhost:8080/save?mywidget.hidden=1&mywidget.number=2
>
> > and these fail validation (as they should), redirecting back to index
> >http://localhost:8080/save?mywidget.hidden=1&mywidget.number=foo
> >http://localhost:8080/save?mywidget.hidden=&mywidget.number=2
> >http://localhost:8080/save?mywidget.number=2
>
> > But this url doesn't fail at all, and goes straight to the save
> > method, apparently bypassing validation.
>
> >http://localhost:8080/save
>
> > Any thoughts as to what's going on here?
>
> why you do this with a compound? is only an example i hope.
>
> i cannot see the error.
> any way if i'm not wrong the problem is validation system,
> i'm not sure the CompoundWidget can use validation in this manner...
>
> Glauco
>

It's an example, but it relates to a real problem that we are seeing
in TGCaptcha. TGCaptcha does essentially the same thing, but with a
bit more complicated CompoundFormField and Schema. However, the error/
behavior is similar to what is in the example. If someone crafts an
url or form without the entire captcha field, then validation seems to
skip the widget, and passes it on to the destination controller as if
the captcha was successful.

Diez B. Roggisch

unread,
Nov 27, 2007, 10:10:31 AM11/27/07
to turbo...@googlegroups.com

Looks like a bug then - can you file a ticket? The coolest thing would be a
short demo-app that exposes the desired behavior, by e.g. having two or three
links in the welcome-template that one could test. Or - even better - tests
in the project, I would then try and see if I can rework them into the core
tests.

Diez

Patrick Lewis

unread,
Nov 28, 2007, 2:51:26 AM11/28/07
to TurboGears
In putting together some tests, I ran into something interesting
(well, for me anyways). If I explicitly name the widget in the method
parameters, everything works as expected. So, if I change my example
save controller to:

def save(self, mywidget={}, **kw):
return dict(kw=kw, controller='save')

then everything is just fine.

I guess I don't know what the proper/expected behavior should be. Is
this still a bug?

Diez B. Roggisch

unread,
Nov 29, 2007, 4:15:08 AM11/29/07
to turbo...@googlegroups.com
Patrick Lewis schrieb:

I'd say so, yes - because when for whatever reason there need to be
properly named parameters, there should at least warnings if not more in
case you don't supply them.

Diez

Patrick Lewis

unread,
Nov 29, 2007, 6:15:21 AM11/29/07
to TurboGears
On Nov 29, 4:15 am, "Diez B. Roggisch" <de...@web.de> wrote:
> Patrick Lewis schrieb:
> > I guess I don't know what the proper/expected behavior should be. Is
> > this still a bug?
>
> I'd say so, yes - because when for whatever reason there need to be
> properly named parameters, there should at least warnings if not more in
> case you don't supply them.
>
> Diez

Ok, ticket filed.
http://trac.turbogears.org/ticket/1621

Thanks.
Reply all
Reply to author
Forward
0 new messages