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

Opened 11 years ago

Last modified 10 years ago

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

Reported by: alevinsn Owned by: 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 Download (386 bytes) - added by TimurIzhbulatov 11 years ago.
Fix for remainder returned from lookup

Change History

Changed 11 years ago by TimurIzhbulatov

Fix for remainder returned from lookup

comment:1 Changed 11 years ago 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.

comment:2 Changed 10 years ago by mramm

  • Priority changed from normal to highest
  • Milestone changed from 1.9.7a5 to 2.0b1

Agreed.

comment:3 Changed 10 years ago by mramm

  • Keywords sprint added

comment:4 Changed 10 years ago by mramm

fixed in r5877

comment:5 Changed 10 years ago by mramm

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