#2279: TGController doesn't handle __before__ and __after__ correctly
------------------------+---------------------------------------------------
 Reporter:  kikidonk    |       Owner:        
     Type:  defect      |      Status:  new   
 Priority:  normal      |   Milestone:  2.0rc1
Component:  TurboGears  |     Version:  trunk 
 Severity:  major       |    Keywords:        
------------------------+---------------------------------------------------
 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 ?

-- 
Ticket URL: <http://trac.turbogears.org/ticket/2279>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "TurboGears Tickets" group.
This group is read-only. No posting by normal members allowed.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears-tickets?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to