Ticket #1987 (closed defect: fixed)
[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
Change History
Changed 3 years ago by TimurIzhbulatov
-
attachment
lookup-fix.diff
added
comment:1 Changed 3 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.
Fix for remainder returned from lookup