From 3b5f3f52b492b779eae50cd82cd9425c68e9406c Mon Sep 17 00:00:00 2001 From: Massimiliano della Rovere Date: Sat, 21 Mar 2015 18:14:33 +0100 Subject: [PATCH] Please update the file "handler.py" Every time a request interacts with the DB via SQLAlchemy and causes an error (e.g. breaking a unique constraint, non-existent column, etc), a RuntimeError is raised by Tornado because the self.finish() method is called twice in Tornado Restless. This patch assures that in the "patch", "delete", "put", "post", "get" methods call "self.finish(result)" only once. You can find a detailed description of the causes in https://github.com/tornado-utils/tornado-restless/issues/10 --- tornado_restless/handler.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tornado_restless/handler.py b/tornado_restless/handler.py index 844f50d..65877a4 100644 --- a/tornado_restless/handler.py +++ b/tornado_restless/handler.py @@ -244,7 +244,8 @@ def patch(self, instance_id: str=None): result = self.patch_single(self.parse_pk(instance_id)) self._call_postprocessor(result=result) - self.finish(result) + if not self._finished: + self.finish(result) def patch_many(self) -> dict: """ @@ -364,7 +365,8 @@ def delete(self, instance_id: str=None): result = self.delete_single(self.parse_pk(instance_id)) self._call_postprocessor(result=result) - self.finish(result) + if not self._finished: + self.finish(result) def delete_many(self) -> dict: """ @@ -455,7 +457,8 @@ def put(self, instance_id: str=None): result = self.put_single(self.parse_pk(instance_id)) self._call_postprocessor(result=result) - self.finish(result) + if not self._finished: + self.finish(result) put_many = patch_many put_single = patch_single @@ -480,7 +483,8 @@ def post(self, instance_id: str=None): result = self.post_single() self._call_postprocessor(result=result) - self.finish(result) + if not self._finished: + self.finish(result) def post_single(self): """ @@ -691,7 +695,8 @@ def get(self, instance_id: str=None): result = self.get_single(self.parse_pk(instance_id)) self._call_postprocessor(result=result) - self.finish(result) + if not self._finished: + self.finish(result) def get_single(self, instance_id: list) -> dict: """