[IMP] base: Clear precommits on test cleanup
Precommit hooks would stock data until a call to ``cr.flush`` was made. Notably, this happens when the ``assertRaises`` method is called. Functions were applied on records already cleared from the cache. This change adds a cleanup call for `TransactionCase` as it keeps the same cursor for all tests. Cursor precommits can now be safely executed inside tests. Task-2834304 Forward port of #117555 closes odoo/odoo#118290 X-original-commit: ff5d0c75fcea5842c5236b1b3f7480ef5a3dc415 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Signed-off-by: Thiry Renaud (reth) <reth@odoo.com>
This commit is contained in:
+12
-1
@@ -28,7 +28,7 @@ import time
|
||||
import unittest
|
||||
from . import case
|
||||
import warnings
|
||||
from collections import defaultdict
|
||||
from collections import defaultdict, deque
|
||||
from concurrent.futures import Future, CancelledError, wait
|
||||
try:
|
||||
from concurrent.futures import InvalidStateError
|
||||
@@ -735,6 +735,17 @@ class TransactionCase(BaseCase):
|
||||
|
||||
self.addCleanup(self.registry.clear_caches)
|
||||
|
||||
# This prevents precommit functions and data from piling up
|
||||
# until cr.flush is called in 'assertRaises' clauses
|
||||
# (these are not cleared in self.env.clear or envs.clear)
|
||||
cr = self.env.cr
|
||||
|
||||
def _reset(cb, funcs, data):
|
||||
cb._funcs = funcs
|
||||
cb.data = data
|
||||
for callback in [cr.precommit, cr.postcommit, cr.prerollback, cr.postrollback]:
|
||||
self.addCleanup(_reset, callback, deque(callback._funcs), dict(callback.data))
|
||||
|
||||
# flush everything in setUpClass before introducing a savepoint
|
||||
self.env.flush_all()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user