Hi,

Nothing like a bug report with some code that demos the problem!

I've fixed this in svn (both 0.9 and the 0.8 branch).

Kevin

On 12/6/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> Here's a short test program that seems to show inconsistent handling
> of formencode's chained_validators.
>
> I'm running TurboGears 0.8a5 -- I don't have 0.9 to test against, sorry.
>
> The problem seems to be that an Invalid exception thrown from a
> chained_validator is ignored when running under TurboGears, but
> raised (correctly, it seems to me), when using formencode directly.
>
> I am new to both these frameworks and therefore may be
> misunderstanding something.
>
> --Kitto
>
>
> #!/usr/bin/env python
>
> import turbogears
> from turbogears.tests import util
> from formencode import validators, Schema, Invalid
> import cherrypy
>
> class MyCV(Schema):
>
>      def _to_python(self, values, state):
>          return values
>
>      def validate_python(self, values, state):
>          print "inside MyCV.validate_python"
>          raise Invalid('invalid', values, state)
>
> class MySchema(Schema):
>      x = validators.Int()
>      chained_validators = [MyCV()]
>
> class Root(turbogears.controllers.Root):
>
>      @turbogears.expose(format='json', validators=MySchema())
>      def index(self, x):
>          return dict(x=x)
>
> def test_formencode():
>      schema = MySchema()
>      try:
>          schema.to_python(dict(x=1))
>      except Invalid:
>          print "exception raised as expected."
>      else:
>          print "error: no exception raised."
>
> def test_turbogears():
>      cherrypy.root = Root()
>      #print util.call(cherrypy.root.index, x=1, s='foo')
>      util.createRequest('/?x=1')
>      print cherrypy.response.body[0]
>      print "why didn't i get an exception?"
>
> if __name__ == '__main__':
>      test_formencode()
>      test_turbogears()
>
>


--
Kevin Dangoor
Author of the Zesty News RSS newsreader

email: [EMAIL PROTECTED]
company: http://www.BlazingThings.com
blog: http://www.BlueSkyOnMars.com

Reply via email to