Skip to content

Conversation

lmignon
Copy link
Contributor

@lmignon lmignon commented Jun 16, 2025

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.

forward port of #538

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.
@lmignon lmignon added this to the 18.0 milestone Jun 16, 2025
@lmignon
Copy link
Contributor Author

lmignon commented Jun 16, 2025

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 18.0-ocabot-merge-pr-543-by-lmignon-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit a770f5d into OCA:18.0 Jun 16, 2025
7 checks passed
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 356af31. Thanks a lot for contributing to OCA. ❤️

@lmignon lmignon deleted the oca-port-fastapi-17.0-to-18.0-2610ba branch June 16, 2025 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants