From: Ben Darnell Date: Fri, 24 May 2013 03:52:19 +0000 (-0400) Subject: Fix regression in async prepare: don't continue of prepare called finish. X-Git-Tag: v3.1.0~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a965b3603a276c8c5df49924c6c5e4df42db9337;p=thirdparty%2Ftornado.git Fix regression in async prepare: don't continue of prepare called finish. --- diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index 018004baf..74eec11e9 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -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') diff --git a/tornado/web.py b/tornado/web.py index e7015c6d6..2ede8d32d 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -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: