Skip to content
Snippets Groups Projects
Commit 707522cb authored by Toufik Ben Jaa's avatar Toufik Ben Jaa Committed by Olivier Dony
Browse files

[FIX] sql_db: flush when no `uid` in environment

- A bug has been introduced by the PR https://github.com/odoo/odoo/pull/46719


  This issue prevented flushes to database when no `uid` is set in the
  current environment.
  This happens when database changes are made in `auth="none"` routes.
  In a MonoDB setup this was working because Odoo consider `None`, `False` as
  `null` and was always bound to a database.

  Nothing prevents to write `null` in the columns `create_uid` and
  `write_uid` in database.
  The PR that introduced the bug wanted to block the cases where
  `uid` is an instance of the class `RequestUID` to avoid `Cannot adapt
  type` errors.
  So testing that `uid` is an integer isn't enough.

  Two fixes were possible here, either check if `uid` is an instance
  of the class `RequestUID` or if it is either an integer, `False` or `None`.

  To avoid noise and imports from `odoo`, we test that `uid` is an instance
  of `None`.
  The case where it is `False` is already tested in the python code:

  ```python
	isinstance(env.uid, int)
  ```

(manual) forward-port of odoo/odoo#48685

closes odoo/odoo#48693

Signed-off-by: default avatarToufik Benjaa (tbe) <tbe@odoo.com>
Signed-off-by: default avatarOlivier Dony (odo) <odo@openerp.com>
parent d05c8136
No related branches found
No related tags found
No related merge requests found
......@@ -65,7 +65,7 @@ def flush_env(cr):
""" Retrieve and flush an environment corresponding to the given cursor """
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):
if env.cr is cr and (isinstance(env.uid, int) or env.uid is None):
env['base'].flush()
break
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment