[FIX] core: preferably flush() with an env with a real uid
This fixes a crash in some controllers with `auth='None'` where some updates are flushed with an environment where `uid=None`. When there is an environment with a real uid, preferably use it. closes odoo/odoo#59658 X-original-commit: 2795c86df54389b858a454cbc1782b1f34f3ba4f Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
This commit is contained in:
+9
-4
@@ -66,13 +66,18 @@ def flush_env(cr, *, clear=True):
|
||||
""" Retrieve and flush an environment corresponding to the given cursor.
|
||||
Also clear the environment if ``clear`` is true.
|
||||
"""
|
||||
env_to_flush = None
|
||||
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
|
||||
env_to_flush = env
|
||||
if env.uid is not None:
|
||||
break # prefer an environment with a real uid
|
||||
|
||||
if env_to_flush is not None:
|
||||
env_to_flush['base'].flush()
|
||||
if clear:
|
||||
env_to_flush.clear() # clear remaining new records to compute
|
||||
|
||||
def clear_env(cr):
|
||||
""" Retrieve and clear an environment corresponding to the given cursor """
|
||||
|
||||
Reference in New Issue
Block a user