diff options
| author | Raphael Collet <rco@odoo.com> | 2020-10-06 09:12:05 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-10-09 13:39:02 +0000 |
| commit | 507295ca80e8eac9c75714f41b599d9e2e8a2549 (patch) | |
| tree | eaa77a0f05d55770f13f3a9565c0d2f6a544044a /odoo/sql_db.py | |
| parent | 7f0e5c0570a7a5622f73e851fbc2beb02c557a1d (diff) | |
[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#59650
X-original-commit: 2795c86df54389b858a454cbc1782b1f34f3ba4f
Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo/sql_db.py')
| -rw-r--r-- | odoo/sql_db.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/odoo/sql_db.py b/odoo/sql_db.py index ce49fb6a60a..1c15f4e4a2d 100644 --- a/odoo/sql_db.py +++ b/odoo/sql_db.py @@ -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 """ |
