Skip to content

Commit

Permalink
[FIX] tests dont generate traceback on aborted test requests
Browse files Browse the repository at this point in the history
bzr revid: al@openerp.com-20140317124343-kgesa5c215z19vpn
  • Loading branch information
antonylesuisse committed Mar 17, 2014
1 parent d3c7750 commit 09deba4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 5 additions & 5 deletions openerp/sql_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Cursor(object):
def check(f):
@wraps(f)
def wrapper(self, *args, **kwargs):
if self.__closed:
if self._closed:
msg = 'Unable to use a closed cursor.'
if self.__closer:
msg += ' It was closed at %s, line %s' % self.__closer
Expand All @@ -165,7 +165,7 @@ def __init__(self, pool, dbname, serialized=True):
self.sql_log = _logger.isEnabledFor(logging.DEBUG)

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
self._pool = pool
self.dbname = dbname
Expand All @@ -180,7 +180,7 @@ def __init__(self, pool, dbname, serialized=True):
self.__caller = frame_codeinfo(currentframe(),2)
else:
self.__caller = False
self.__closed = False # real initialisation value
self._closed = False # real initialisation value
self.autocommit(False)
self.__closer = False

Expand All @@ -189,7 +189,7 @@ def __init__(self, pool, dbname, serialized=True):
self.cache = {}

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.
# The cursor will be deleted by the garbage collector,
# but the database connection is not put back into the connection
Expand Down Expand Up @@ -302,7 +302,7 @@ def _close(self, leak=False):
# 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._closed = True

# Clean the underlying connection.
self._cnx.rollback()
Expand Down
5 changes: 4 additions & 1 deletion openerp/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import unittest2
import urllib2
import xmlrpclib

from datetime import datetime, timedelta

import werkzeug

import openerp

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -46,6 +47,8 @@ def acquire_test_cursor(session_id):
cr = HTTP_SESSION.get(session_id)
if cr:
cr._test_lock.acquire()
if cr._closed:
werkzeug.exceptions.abort(500)
return cr

def release_test_cursor(cr):
Expand Down

0 comments on commit 09deba4

Please sign in to comment.