Skip to content

Commit 7a2f0bb

Browse files
grindtildeathlmignon
authored andcommitted
[FIX] fastapi: Flush before exiting Fastapi environment
As the fastapi dispatcher is altering the public request's environment before calling the endpoint, it will reuse the same DB cursor from this environment. Therefore, if fields are being marked to be recomputed during the execution of the fastapi endpoint, these will not be recomputed until the cursor is being commited, what happens when we are not anymore authenticated through as fastapi user. This means the recomputation of computed fields will be executed with the public user, what could potentially lead to inconsistencies or result in an AccessError. By calling flush before exiting the contextmanager yielding the altered Odoo environment, we ensure all the pending computations are executed while being authenticated with the fastapi user which must have more access rights than the public user.
1 parent 4b8bb1d commit 7a2f0bb

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

fastapi/fastapi_dispatcher.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,10 @@ def _manage_odoo_env(self, uid=None):
115115
token = odoo_env_ctx.set(env)
116116
try:
117117
yield
118+
# Flush here to ensure all pending computations are being executed with
119+
# authenticated fastapi user before exiting this context manager, as it
120+
# would otherwise be done using the public user on the commit of the DB
121+
# cursor, what could potentially lead to inconsistencies or AccessError.
122+
env.flush_all()
118123
finally:
119124
odoo_env_ctx.reset(token)

0 commit comments

Comments
 (0)