diff --git a/momoko/connection.py b/momoko/connection.py index 79d9ab1..5959def 100644 --- a/momoko/connection.py +++ b/momoko/connection.py @@ -457,7 +457,7 @@ def when_available(fut): log.debug("Obtained connection: %s", conn.fileno) try: future_or_result = method(conn, *args, **kwargs) - except psycopg2.Error as error: + except Exception as error: log.debug("Method failed synchronously") return self._retry(retry, when_available, conn, keep, future) diff --git a/tests.py b/tests.py index ca924b8..ac02cd7 100644 --- a/tests.py +++ b/tests.py @@ -580,6 +580,15 @@ def test_getconn_manage_with_exception(self): pass self.assertEqual(len(self.db.conns.busy), 0, msg="Some connections were not recycled") + @gen_test + def test_non_psycopg2_errors(self): + """Testing that non-psycopg2 errors are catched properly""" + try: + sql = yield self.conn.execute("SELECT %s %s;", (1,)) + except IndexError: + pass + self.assertEqual(len(self.db.conns.busy), 0, msg="Some connections were not recycled") + class MomokoPoolDataTestProxy(ProxyMixIn, MomokoPoolDataTest): pass