Ticket #2313 (closed defect: fixed)
[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
Change History
comment:3 Changed 3 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 3 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 2 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 2 years ago by jorge.vargas
- Version changed from 2.0rc1 to 2.0.3
- Milestone changed from 2.x to 2.* bugfix

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