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 #2313 (closed defect: fixed)

Opened 10 years ago

Last modified 9 years ago

[PATCH] Validate decorator does not work with url args

Reported by: chrisz Owned by:
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 Download (1.3 KB) - added by anthonyt 10 years ago.
fix off by one error

Change History

comment:1 Changed 10 years ago by chrisz

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

comment:2 Changed 10 years ago by percious

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

Changed 10 years ago by anthonyt

fix off by one error

comment:3 Changed 10 years ago by anthonyt

  • Status changed from closed to reopened
  • Resolution fixed 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.

comment:4 Changed 10 years ago by anthonyt

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

comment:5 Changed 10 years ago 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.

comment:6 Changed 10 years ago by jorge.vargas

  • Version changed from 2.0rc1 to 2.0.3
  • Milestone changed from 2.x to 2.* bugfix

comment:7 Changed 9 years ago by percious

  • Status changed from reopened to closed
  • Resolution set to fixed

comment:8 Changed 9 years ago by percious

  • Milestone changed from 2.* bugfix to 2.1b1
Note: See TracTickets for help on using tickets.