Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2356 (closed defect: invalid)

Opened 10 years ago

Last modified 9 years ago

@validate decorator does not work if error_handler is not set.

Reported by: vjaaskel Owned by:
Priority: normal Milestone: 2.1rc1
Component: TurboGears Version: 2.0
Severity: normal Keywords:
Cc:

Description

It seems that the @validate decorator doesn't do any validation if the error_handler action is not set. A simple test case can be reproduced by adding the following actions to the TG2 quick start root controller:

    @expose()
    def ok(self):
        flash('Validation passed.')
        redirect('/index')

    @expose()
    def fail(self, **kw):
        flash('Validation failed.', 'error')
        redirect('/index')

    @expose()
    # @validate(validators=dict(foo=validators.NotEmpty()), error_handler=fail) # Works as expected
    @validate(validators=dict(foo=validators.NotEmpty())) # doesn't work
    def test_validation(self, foo=None):
        redirect('/ok')

The test_validation can now be called with 'foo' empty or not set, and still get redirected to the /ok page. With more complex validators, an invalid value can be set to urlargs, POST or GET variables and still pass validation.

If the error_handler is set, validation works as expected.

Tested with tg.devtools 2.0.2

Change History

comment:1 Changed 10 years ago by jorge.vargas

  • Severity changed from major to normal
  • Milestone set to 2.1

This should be verified and fixed for the 2.1 release

comment:2 Changed 9 years ago by vjaaskel

  • Status changed from new to closed
  • Resolution set to invalid

This was just a misunderstanding on how the error handling is supposed to work if error_handler function is not set. I didn't expect the function itself to be used as the error handler. The validation works and pylons.c.form_errors contain expected errors in the test_validation function.

comment:3 Changed 9 years ago by percious

  • Milestone changed from 2.1 to 2.1rc1
Note: See TracTickets for help on using tickets.