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

Opened 10 years ago

Last modified 10 years ago

TGController doesn't handle __before__ and __after__ correctly

Reported by: kikidonk Owned by:
Priority: normal Milestone: 2.0rc1
Component: TurboGears Version: trunk
Severity: major Keywords:
Cc:

Description

There seems to be several problems with TGController in the way it handles before/after

The code does:

if func_name == '__before__' or func_name == '__after__':
    if hasattr(controller.im_class, '__before__'):
        return controller.im_self.__before__(*args)
    if hasattr(controller.im_class, '__after__'):
        return controller.im_self.__before__(*args)
return

Both here: http://trac.turbogears.org/browser/trunk/tg/controllers.py#L447 and here: http://trac.turbogears.org/browser/trunk/tg/controllers.py#L769

It should do:

if func_name == '__before__' or func_name == '__after__': 
    if func_name == '__before__' and hasattr(controller.im_class, '__before__'):
        return controller.im_self.__before__(*args)
    if func_name == '__after__' and hasattr(controller.im_class, '__after__'):
        return controller.im_self.__after__(*args)
return

Note: There are actually 2 bugs: the missing check for func_name == xxx before each call, and the call to __after__ instead of __before__ in the second branch.

The result is that before is being called twice for each request, and after is never called !

Also i wonder if checking for hasattr() makes any sense since the before/after methods are declared (although empty) in the ObjectDispatchController? so that it will always return true, unless i'm missing something ?

Attachments

tg-controllers.diff Download (1.7 KB) - added by kikidonk 10 years ago.
Patch

Change History

Changed 10 years ago by kikidonk

Patch

comment:1 Changed 10 years ago by percious

  • Status changed from new to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.