[FIX] tests dont generate traceback on aborted test requests

bzr revid: al@openerp.com-20140317124343-kgesa5c215z19vpn
This commit is contained in:
Antony Lesuisse 2014-03-17 13:43:43 +01:00
parent d3c7750b96
commit 09deba4826
2 changed files with 9 additions and 6 deletions

View File

@ -148,7 +148,7 @@ class Cursor(object):
def check(f): def check(f):
@wraps(f) @wraps(f)
def wrapper(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
if self.__closed: if self._closed:
msg = 'Unable to use a closed cursor.' msg = 'Unable to use a closed cursor.'
if self.__closer: if self.__closer:
msg += ' It was closed at %s, line %s' % self.__closer msg += ' It was closed at %s, line %s' % self.__closer
@ -165,7 +165,7 @@ class Cursor(object):
self.sql_log = _logger.isEnabledFor(logging.DEBUG) self.sql_log = _logger.isEnabledFor(logging.DEBUG)
self.sql_log_count = 0 self.sql_log_count = 0
self.__closed = True # avoid the call of close() (by __del__) if an exception self._closed = True # avoid the call of close() (by __del__) if an exception
# is raised by any of the following initialisations # is raised by any of the following initialisations
self._pool = pool self._pool = pool
self.dbname = dbname self.dbname = dbname
@ -180,7 +180,7 @@ class Cursor(object):
self.__caller = frame_codeinfo(currentframe(),2) self.__caller = frame_codeinfo(currentframe(),2)
else: else:
self.__caller = False self.__caller = False
self.__closed = False # real initialisation value self._closed = False # real initialisation value
self.autocommit(False) self.autocommit(False)
self.__closer = False self.__closer = False
@ -189,7 +189,7 @@ class Cursor(object):
self.cache = {} self.cache = {}
def __del__(self): def __del__(self):
if not self.__closed and not self._cnx.closed: if not self._closed and not self._cnx.closed:
# Oops. 'self' has not been closed explicitly. # Oops. 'self' has not been closed explicitly.
# The cursor will be deleted by the garbage collector, # The cursor will be deleted by the garbage collector,
# but the database connection is not put back into the connection # but the database connection is not put back into the connection
@ -302,7 +302,7 @@ class Cursor(object):
# collected as fast as they should). The problem is probably due in # collected as fast as they should). The problem is probably due in
# part because browse records keep a reference to the cursor. # part because browse records keep a reference to the cursor.
del self._obj del self._obj
self.__closed = True self._closed = True
# Clean the underlying connection. # Clean the underlying connection.
self._cnx.rollback() self._cnx.rollback()

View File

@ -15,9 +15,10 @@ import time
import unittest2 import unittest2
import urllib2 import urllib2
import xmlrpclib import xmlrpclib
from datetime import datetime, timedelta from datetime import datetime, timedelta
import werkzeug
import openerp import openerp
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -46,6 +47,8 @@ def acquire_test_cursor(session_id):
cr = HTTP_SESSION.get(session_id) cr = HTTP_SESSION.get(session_id)
if cr: if cr:
cr._test_lock.acquire() cr._test_lock.acquire()
if cr._closed:
werkzeug.exceptions.abort(500)
return cr return cr
def release_test_cursor(cr): def release_test_cursor(cr):