From b15c2c2f23f921108e1be8e994d561e7368be469 Mon Sep 17 00:00:00 2001 From: Zaar Hai Date: Sun, 16 Nov 2014 10:12:56 +0200 Subject: [PATCH] Catching ALL types of early error. Fixes #79. Its important to catch any type of early error and pass it back properly to give inner callback a chance to return connection back to free pool. Signed-off-by: Zaar Hai --- momoko/connection.py | 2 +- tests.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/momoko/connection.py b/momoko/connection.py index 76e4780..c241731 100644 --- a/momoko/connection.py +++ b/momoko/connection.py @@ -606,7 +606,7 @@ def wrapper(self, *args, **kwargs): callback = kwargs.get("callback", _dummy_callback) try: return func(self, *args, **kwargs) - except psycopg2.Error as error: + except Exception as error: callback(None, error) return wrapper diff --git a/tests.py b/tests.py index 6d1e180..d60830c 100644 --- a/tests.py +++ b/tests.py @@ -326,6 +326,16 @@ def func(): self.assert_raises(psycopg2.ProgrammingError, self.run_gen, func) + def test_op_early_exception(self): + """Testing that Op propagates early exceptions properly""" + @gen.engine + def func(): + cursor = yield momoko.Op(self.db.execute, 'SELECT %s FROM %s', ()) + self.stop() + + self.assert_raises(IndexError, self.run_gen, func) + self.assertFalse(self.db._conns.busy, msg="Busy connction was not returned to pool after exception") + def test_wait_op(self): """Testing WaitOp""" @gen.engine