[FIX] free the database connecion in all cases
lp bug: https://launchpad.net/bugs/307069 fixed bzr revid: christophe@tinyerp.com-20081212132416-4kt1xh9nmka7r6a1
This commit is contained in:
parent
6675a3709c
commit
43f0fffd07
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue