Skip to content

Commit 3c109ef

Browse files
committed
Tough method should get proper error message after connection was lost.
1 parent abb1c54 commit 3c109ef

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

DBUtils/SteadyDB.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def close(self):
436436
self._closed = True
437437

438438
def _get_tough_method(self, name):
439-
"""Return a "tough" version of the method."""
439+
"""Return a "tough" version of the given cursor method."""
440440
def tough_method(*args, **kwargs):
441441
execute = name.startswith('execute')
442442
try:
@@ -493,14 +493,21 @@ def tough_method(*args, **kwargs):
493493
result = method2(*args, **kwargs)
494494
if execute:
495495
self._clearsizes()
496-
except Exception:
497-
pass
496+
except error.__class__: # same execution error
497+
use2 = False
498+
except Exception, error: # other execution errors
499+
use2 = True
498500
else:
501+
use2 = True
502+
error = None
503+
if use2:
499504
self.close()
500505
self._con._close()
501506
self._con._store(con2)
502507
self._cursor = cursor2
503508
self._con._usage += 1
509+
if error:
510+
raise error # raise the other error
504511
return result
505512
try:
506513
cursor2.close()

DBUtils/Tests/TestSteadyDB.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,15 @@ def test8_SteadyDBConnectionFailures(self):
470470
db.close()
471471
db.cursor()
472472

473+
def test9_SteadyDBConnectionFailureError(self):
474+
db = SteadyDBconnect(dbapi)
475+
cursor = db.cursor()
476+
db.close()
477+
cursor.execute('select test')
478+
cursor = db.cursor()
479+
db.close()
480+
self.assertRaises(ProgrammingError, cursor.execute, 'error')
481+
473482

474483
if __name__ == '__main__':
475484
unittest.main()

0 commit comments

Comments
 (0)