Commits

Anonymous committed 14b267b

Fix for #953 - when handlers take arguments that have default values, don't count those arguments as missing. This only showed up when the handler itself raised a TypeError.

Comments (0)

Files changed (2)

cherrypy/_cpdispatch.py

             varkw_usage += 1
             extra_kwargs.add(key)
 
+    # figure out which args have defaults.
+    args_with_defaults = args[-len(defaults or []):]
     for i, val in enumerate(defaults or []):
         # Defaults take effect only when the arg hasn't been used yet.
-        if arg_usage[args[i]] == 0:
-            arg_usage[args[i]] += 1
+        if arg_usage[args_with_defaults[i]] == 0:
+            arg_usage[args_with_defaults[i]] += 1
 
     missing_args = []
     multiple_args = []

cherrypy/test/test_request_obj.py

             raise TypeError("Client Error")
         raise_type_error.exposed = True
 
+        def raise_type_error_with_default_param(self, x, y=None):
+            return '%d' % 'a' # throw an exception
+        raise_type_error_with_default_param.exposed = True
 
     def callable_error_page(status, **kwargs):
         return "Error %s - Well, I'm very sorry but you haven't paid!" % status
                 else:
                     self.assertInBody("Not Found")
 
-
         # In the case that a handler raises a TypeError we should
         # let that type error through.
         for uri in (
                 '/paramerrors/raise_type_error',
+                '/paramerrors/raise_type_error_with_default_param?x=0',
+                '/paramerrors/raise_type_error_with_default_param?x=0&y=0',
             ):
-            self.getPage(uri, method='POST', body=body)
+            self.getPage(uri, method='GET')
             self.assertStatus(500)
             self.assertTrue('Client Error', self.body)