]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix regression in async prepare: don't continue of prepare called finish.
authorBen Darnell <ben@bendarnell.com>
Fri, 24 May 2013 03:52:19 +0000 (23:52 -0400)
committerBen Darnell <ben@bendarnell.com>
Fri, 24 May 2013 03:52:19 +0000 (23:52 -0400)
tornado/test/web_test.py
tornado/web.py

index 018004baf7546716b595e6daccb44f004ee1e5da..74eec11e964d08702ec80ff013442416ee714a74 100644 (file)
@@ -1498,3 +1498,20 @@ class PatchMethodTest(SimpleHandlerTestCase):
         response = self.fetch('/', method='OTHER',
                               allow_nonstandard_methods=True)
         self.assertEqual(response.body, b'other')
+
+
+@wsgi_safe
+class FinishInPrepareTest(SimpleHandlerTestCase):
+    class Handler(RequestHandler):
+        def prepare(self):
+            self.finish('done')
+
+        def get(self):
+            # It's difficult to assert for certain that a method did not
+            # or will not be called in an asynchronous context, but this
+            # will be logged noisily if it is reached.
+            raise Exception('should not reach this method')
+
+    def test_finish_in_prepare(self):
+        response = self.fetch('/')
+        self.assertEqual(response.body, b'done')
index e7015c6d6f47379697377d9581da4865dce1117b..2ede8d32deeb81a5ea861c6f7e26e1b6e8275285 100644 (file)
@@ -1154,9 +1154,10 @@ class RequestHandler(object):
             self._handle_request_exception(e)
 
     def _execute_method(self):
-        method = getattr(self, self.request.method.lower())
-        self._when_complete(method(*self.path_args, **self.path_kwargs),
-                            self._execute_finish)
+        if not self._finished:
+            method = getattr(self, self.request.method.lower())
+            self._when_complete(method(*self.path_args, **self.path_kwargs),
+                                self._execute_finish)
 
     def _execute_finish(self):
         if self._auto_finish and not self._finished: