diff --git a/fastapi/fastapi_dispatcher.py b/fastapi/fastapi_dispatcher.py index 0ded74c3d..bc64898d7 100644 --- a/fastapi/fastapi_dispatcher.py +++ b/fastapi/fastapi_dispatcher.py @@ -115,5 +115,10 @@ def _manage_odoo_env(self, uid=None): token = odoo_env_ctx.set(env) try: yield + # Flush here to ensure all pending computations are being executed with + # authenticated fastapi user before exiting this context manager, as it + # would otherwise be done using the public user on the commit of the DB + # cursor, what could potentially lead to inconsistencies or AccessError. + env.flush_all() finally: odoo_env_ctx.reset(token)