Ticket #1987 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

[PATCH] Bug in controllers.py _find_object() function causes problems for a controller's lookup() method in TG2.0

Reported by: alevinsn Assigned to: anonymous
Priority: highest Milestone: 2.0b1
Component: TurboGears Version: trunk
Severity: normal Keywords: sprint
Cc:

Description

At http://www.turbogears.org/2.0/docs/main/Controllers.html#the-new-tg2-lookup-method, it describes how to make use of TG2.0's new lookup() method in a controller. The code mostly works, but runs up against a bug in the _find_object() function in tg/controllers.py. Specifically, the problem occurs on line 439:

if not remainder or remainder == ['']:

The problem is that remainder, as passed into the lookup() method, is actually a tuple, not a list. So this check always fails and it never gets to the index() method for the sub-controller.

The line should instead probably look like the following:

if not remainder or remainder == ('',):

I was able to workaround this problem in my implementation of the lookup() method as follows:

    def lookup(self, blah, *remainder):
        subController = SubController(blah)
        remainderList = []
        for item in remainder:
            remainderList.append(item)
        return subController, remainderList

Attachments

lookup-fix.diff (386 bytes) - added by TimurIzhbulatov on 09/28/08 22:00:30.
Fix for remainder returned from lookup

Change History

09/28/08 22:00:30 changed by TimurIzhbulatov

  • attachment lookup-fix.diff added.

Fix for remainder returned from lookup

09/28/08 22:01:12 changed by TimurIzhbulatov

  • summary changed from Bug in controllers.py _find_object() function causes problems for a controller's lookup() method in TG2.0 to [PATCH] Bug in controllers.py _find_object() function causes problems for a controller's lookup() method in TG2.0.

Well, it looks like inside tg/controllers.py the remainder variables are *supposed* to be lists — this comparison statement and the call of reminder.pop() in _find_object point to that. The root cause the bug is that the *remainder extended argument of a lookup method is normally unpacked to a tuple when the method is called.

So, I think the fix should just make sure that the remainder returned from object's lookup method is converted to a list.

12/10/08 09:02:46 changed by mramm

  • priority changed from normal to highest.
  • milestone changed from 1.9.7a5 to 2.0b1.

Agreed.

12/12/08 18:02:45 changed by mramm

  • keywords set to sprint.

12/13/08 11:11:34 changed by mramm

fixed in r5877

12/13/08 11:12:05 changed by mramm

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