[FIX] do not relay on _obj to know if the cursor has been closed
lp bug: https://launchpad.net/bugs/330999 fixed bzr revid: christophe@tinyerp.com-20090428141007-td39oa95wk5h5dt7
This commit is contained in:
parent
8e1ab8207c
commit
82b0474328
|
@ -71,7 +71,7 @@ class Cursor(object):
|
|||
|
||||
@wraps(f)
|
||||
def wrapper(self, *args, **kwargs):
|
||||
if not hasattr(self, '_obj'):
|
||||
if self.__closed:
|
||||
raise psycopg2.ProgrammingError('Unable to use the cursor after having closing it')
|
||||
return f(self, *args, **kwargs)
|
||||
return wrapper
|
||||
|
@ -81,6 +81,7 @@ class Cursor(object):
|
|||
self._serialized = serialized
|
||||
self._cnx = pool.getconn()
|
||||
self._obj = self._cnx.cursor(cursor_factory=psycopg1cursor)
|
||||
self.__closed = False
|
||||
self.autocommit(False)
|
||||
self.dbname = pool.dbname
|
||||
|
||||
|
@ -89,7 +90,7 @@ class Cursor(object):
|
|||
self.__caller = tuple(stack()[2][1:3])
|
||||
|
||||
def __del__(self):
|
||||
if hasattr(self, '_obj'):
|
||||
if not self.__closed:
|
||||
if tools.config['log_level'] in (netsvc.LOG_DEBUG, netsvc.LOG_DEBUG_RPC):
|
||||
# Oops. 'self' has not been closed explicitly.
|
||||
# The cursor will be deleted by the garbage collector,
|
||||
|
@ -166,6 +167,7 @@ class Cursor(object):
|
|||
# collected as fast as they should). The problem is probably due in
|
||||
# part because browse records keep a reference to the cursor.
|
||||
del self._obj
|
||||
self.__closed = True
|
||||
self._pool.putconn(self._cnx)
|
||||
|
||||
@check
|
||||
|
|
Loading…
Reference in New Issue