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