summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2020-05-06 12:46:04 +0000
committerRaphael Collet <rco@odoo.com>2020-06-11 14:40:33 +0000
commit4f9efd2eb1481adf8234af6f462e5a7900c089c0 (patch)
tree2be9001a44ebeced020cf38482f47255803f6c86
parent150f68108c0a1570f7b2822a7ba575029160ce4f (diff)
[FIX] core: flushing an environment should not leave things to compute
Upon cursor `commit()`, the pending computations are performed with method `flush()`. However the latter method leaves fields to compute on new records. As the `commit` ends the current transaction, we can clear those pending computations. X-original-commit: d27e98d9048d0cb1250522205286ebc7b7d5ea39
-rw-r--r--odoo/sql_db.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/odoo/sql_db.py b/odoo/sql_db.py
index 5826cd83813..18f3633539d 100644
--- a/odoo/sql_db.py
+++ b/odoo/sql_db.py
@@ -61,12 +61,16 @@ import threading
from inspect import currentframe
-def flush_env(cr):
- """ Retrieve and flush an environment corresponding to the given cursor """
+def flush_env(cr, *, clear=True):
+ """ Retrieve and flush an environment corresponding to the given cursor.
+ Also clear the environment if ``clear`` is true.
+ """
for env in list(Environment.envs):
# don't flush() on another cursor or with a RequestUID
if env.cr is cr and (isinstance(env.uid, int) or env.uid is None):
env['base'].flush()
+ if clear:
+ env.clear() # clear remaining new records to compute
break
def clear_env(cr):
@@ -106,14 +110,14 @@ class BaseCursor:
"""context manager entering in a new savepoint"""
name = uuid.uuid1().hex
if flush:
- flush_env(self)
+ flush_env(self, clear=False)
self.precommit()
self.prerollback.clear()
self.execute('SAVEPOINT "%s"' % name)
try:
yield
if flush:
- flush_env(self)
+ flush_env(self, clear=False)
self.precommit()
self.prerollback.clear()
except Exception: