Ticket #2313 (closed defect: fixed)

Opened 1 year ago

Last modified 7 months ago

[PATCH] Validate decorator does not work with url args

Reported by: chrisz Assigned to:
Priority: high Milestone: 2.1b1
Component: TurboGears Version: 2.0.3
Severity: major Keywords: validate
Cc:

Description

To reproduce the problem, quickstart an application, add the following at the top of controllers/root,

from tg import validate
from formencode import validators

and change the index method of the root controller like this:

    @expose('foo.templates.index')
    @validate(validators=dict(nr=validators.Int()))
    def index(self, nr=None):
        ...

Now run the application and surf to http://localhost:8080/index/1.

The validator should pass, but I'm getting this:

TypeError: index() got multiple values for keyword argument 'nr' 

See also this thread in the tg-trunk mailing list.

Attachments

fix_r6567_t2313.diff (1.3 kB) - added by anthonyt on 06/15/09 22:10:30.
fix off by one error

Change History

04/22/09 04:21:56 changed by chrisz

Seems to have been fixed in percious' dispatch refact branch.

04/23/09 16:08:35 changed by percious

  • status changed from new to closed.
  • resolution set to fixed.

06/15/09 22:10:30 changed by anthonyt

  • attachment fix_r6567_t2313.diff added.

fix off by one error

06/15/09 22:15:40 changed by anthonyt

  • status changed from closed to reopened.
  • resolution deleted.

There's a bug in the fix for this ticket in the 2.0 branch (revision 6567 in svn).

It's an off by one error, where the keyword arguments are placed into the args list at the wrong indexes.

When a decorated action expects arguments (self, foo, bar), it might end up getting arguments (foo, bar) instead.

I've attached a patch that should fix the problem.

It's not as good a solution as the one in the 2.1 branch, but it fixes the bug without any large refactoring.

06/15/09 22:16:56 changed by anthonyt

  • summary changed from Validate decorator does not work with url args to [PATCH] Validate decorator does not work with url args.

11/17/09 10:36:16 changed by jorge.vargas

  • milestone set to 2.x.

The refractoring was due to several other issues. The main one was to make controllers.py into a package for easier maintenance.

Current plans are not to release 2.0.4 and simply release 2.1 so I'm tempted to mark this as a workfix.

12/01/09 22:05:11 changed by jorge.vargas

  • version changed from 2.0rc1 to 2.0.3.
  • milestone changed from 2.x to 2.* bugfix.

01/23/10 15:51:37 changed by percious

  • status changed from reopened to closed.
  • resolution set to fixed.

01/23/10 15:52:07 changed by percious

  • milestone changed from 2.* bugfix to 2.1b1.