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 #2523 (closed defect: migrated)

Opened 9 years ago

Last modified 8 years ago

[PATCH] possibly bug in TurboGears2-2.0.3-py2.5.egg/tg /controllers.py

Reported by: nguyenqmai Owned by:
Priority: normal Milestone: 2.0.* bugfix
Component: TurboGears Version: 2.0.3
Severity: critical Keywords:
Cc:

Description

My RestController? caused TypeError: 'tuple' object does not support item assignment

Module tg.controllers:170 in _perform_call
                      name = argvars[i] 
                           if name in params: 
                               remainder[i] = params[name] 
                               del params[name] 
                   output = controller(*remainder, **dict(params)) 

TypeError: 'tuple' object does not support item assignment 
from tg import expose, flash, require, url, request, redirect 
from tg.controllers import RestController 
class DomainController(RestController): 
        def __init__(self): 
                self._domains = {} 
                self._domains["do.com"] = "do.com" 
                self._domains["dom.com"] = "dom.com" 
                self._domains["doma.com"] = "doma.com" 
                self._domains["domain.com"] = "domain.com" 
        @expose() 
        def get_one(self, domain_id): 
                print "in get_one" 
                return "you can not do anything with [%s] now" % 
(domain_id) 
        @expose() 
        def get_all(self, **dict): 
                print "in get_all" 
                for domain_id in self._domains.keys(): 
                    str_domain_ids += "[%s] " % (domain_id) 
                return str_domain_ids 

Found the problem at line 135 of TurboGears2-2.0.3-py2.5.egg/tg/ controllers.py:

def _perform_call(self, controller, params, remainder=None): 
    .............. 
# issue here because the passed in remainder could be a tuple 
#135:    remainder = remainder or []
    .............. 
#169                    if name in params: 
#170                        remainder[i] = params[name] 

The bug fixed if we convert a potential tuple into a list

def _perform_call(self, controller, params, remainder=None): 
    .............. 
# this took care the problem 
#135    remainder = list(remainder) or []
    .............. 
#169                    if name in params: 
#170                        remainder[i] = params[name] 

The patch is simple

Index: tg/controllers.py
===================================================================
--- tg/controllers.py	(revision 7149)
+++ tg/controllers.py	(working copy)
@@ -132,7 +132,7 @@
         self._initialize_validation_context()
         request.start_response = self.start_response
 
-        remainder = remainder or []
+        remainder = list(remainder) or []
         try:
             if 'tg_format' in params:
                 request.headers['tg_format'] = params['tg_format']

Attachments

tg.controller.diff Download (492 bytes) - added by nguyenqmai 9 years ago.

Change History

Changed 9 years ago by nguyenqmai

comment:1 Changed 9 years ago by nguyenqmai

Test get_all with curl worked fine

curl 127.0.0.1:8080/domains/ 
[doma.com] [dom.com] [do.com] [domain.com] 

Test get_one with curl had problem (full error stack trace attached at the end):

curl 127.0.0.1:8080/domains/wth 
Module tg.controllers:170 in _perform_call
                      name = argvars[i] 
                           if name in params: 
                               remainder[i] = params[name] 
                               del params[name] 
                   output = controller(*remainder, **dict(params)) 

comment:2 Changed 9 years ago by percious

  • Milestone changed from __unclassified__ to 2.0.* bugfix

comment:3 Changed 9 years ago by percious

My recommendation is to upgrade to TG 2.1. 2.1rc1 is out, and 2.1 final shall be released in 2 days!

comment:4 Changed 8 years ago by pedersen

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