summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorP. Christeas <p_christ@hol.gr>2010-11-23 15:58:37 +0200
committerP. Christeas <p_christ@hol.gr>2010-11-23 15:58:37 +0200
commit7d3afa7c0c90bd5d312db0cc977cafa6bd82e73c (patch)
tree99bbcf5bb0e8b4ac36b7291074f91b9092404f0a
parentc67f1746f4f79dc0e4215325b2a15c2d990bf7c3 (diff)
sql_db: Better exceptions.
A closed cursor should behave the same as a closed connection, ie. OperationalError. Also instrument a function we don't expect to be called. bzr revid: p_christ@hol.gr-20101123135837-vkn3ph0e4bz9urf0
-rw-r--r--bin/sql_db.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/bin/sql_db.py b/bin/sql_db.py
index cdc3d0de4b3..89f5cb01c27 100644
--- a/bin/sql_db.py
+++ b/bin/sql_db.py
@@ -28,6 +28,7 @@ from psycopg2.psycopg1 import cursor as psycopg1cursor
from psycopg2.pool import PoolError
import psycopg2.extensions
+import warnings
psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
@@ -71,7 +72,7 @@ class Cursor(object):
@wraps(f)
def wrapper(self, *args, **kwargs):
if self.__closed:
- raise psycopg2.ProgrammingError('Unable to use the cursor after having closed it')
+ raise psycopg2.OperationalError('Unable to use the cursor after having closed it')
return f(self, *args, **kwargs)
return wrapper
@@ -337,10 +338,12 @@ class Connection(object):
def __nonzero__(self):
"""Check if connection is possible"""
try:
+ warnings.warn("You use an expensive function to test a connection.",
+ DeprecationWarning, stacklevel=1)
cr = self.cursor()
cr.close()
return True
- except:
+ except Exception:
return False