Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Commit

Permalink
Catching ALL types of early error. Fixes #79.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
haizaar committed Nov 16, 2014
1 parent 6fb8d14 commit b15c2c2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion momoko/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b15c2c2

Please sign in to comment.