summaryrefslogtreecommitdiff
path: root/bin/sql_db.py
diff options
context:
space:
mode:
authorChristophe Simonis <christophe@tinyerp.com>2008-12-12 14:24:16 +0100
committerChristophe Simonis <christophe@tinyerp.com>2008-12-12 14:24:16 +0100
commit43f0fffd076a60cb53b0dc7831e12b34525ff17f (patch)
tree7dcd04e03165bc54bd8bc6169ea621f45e3c0768 /bin/sql_db.py
parent6675a3709c84eb025f33ca1b27c581bd7493134f (diff)
[FIX] free the database connecion in all cases
lp bug: https://launchpad.net/bugs/307069 fixed bzr revid: christophe@tinyerp.com-20081212132416-4kt1xh9nmka7r6a1
Diffstat (limited to 'bin/sql_db.py')
-rw-r--r--bin/sql_db.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/bin/sql_db.py b/bin/sql_db.py
index a63b2eff205..e88c6b12efb 100644
--- a/bin/sql_db.py
+++ b/bin/sql_db.py
@@ -67,7 +67,7 @@ class Cursor(object):
@wraps(f)
def wrapper(self, *args, **kwargs):
if not hasattr(self, '_obj'):
- raise Exception('Unable to use the cursor after having closing it')
+ raise psycopg2.ProgrammingError('Unable to use the cursor after having closing it')
return f(self, *args, **kwargs)
return wrapper
@@ -78,6 +78,16 @@ class Cursor(object):
self.autocommit(False)
self.dbname = pool.dbname
+ def __del__(self):
+ if hasattr(self, '_obj'):
+ # Oops. 'self' has not been closed explicitly.
+ # The cursor will be deleted by the garbage collector,
+ # but the database connection is not put back into the connection
+ # pool, preventing some operation on the database like dropping it.
+ # This can also lead to a server overload.
+ log('Cursor not closed explicitly', netsvc.LOG_WARNING)
+ self.close()
+
@check
def execute(self, query, params=None):
if params is None:
@@ -136,6 +146,7 @@ class Cursor(object):
sqllogs[type].clear()
process('from')
process('into')
+ self.count = 0
@check
def close(self):