Skip to content

Commit

Permalink
Merge PR #405 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by sbidoul
  • Loading branch information
OCA-git-bot committed Dec 21, 2023
2 parents 880b7dc + 8be7fbb commit f40f84b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion fastapi/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Odoo FastAPI
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d3ecfeda1c0c52b03f8f326849edbfac58a4c724c6e4e2d90e7c5edd6f5207c8
!! source digest: sha256:3c6fc2f30a2e71ad5f97cd59022ea69c1c7a812bc791555ace9206f7c18c82ae
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
7 changes: 6 additions & 1 deletion fastapi/error_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@


def _rollback(request: Request, reason: str) -> None:
cr = odoo_env_ctx.get().cr
env = odoo_env_ctx.get()
cr = env.cr
if cr is not None:
_logger.debug("rollback on %s", reason)
cr.rollback()
# Also close the cursor, so `retrying` in service/model.py does not attempt to
# flush.
if not (env.registry.in_test_mode()):
cr.close()


async def _odoo_user_error_handler(
Expand Down
4 changes: 4 additions & 0 deletions fastapi/readme/newsfragments/405.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
In case of exception in endpoint execution, close the database cursor after rollback.

This is to ensure that the *retrying* method in *service/model.py* does not try
to flush data to the database.
3 changes: 2 additions & 1 deletion fastapi/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -366,7 +367,7 @@ <h1 class="title">Odoo FastAPI</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d3ecfeda1c0c52b03f8f326849edbfac58a4c724c6e4e2d90e7c5edd6f5207c8
!! source digest: sha256:3c6fc2f30a2e71ad5f97cd59022ea69c1c7a812bc791555ace9206f7c18c82ae
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/16.0/fastapi"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-16-0/rest-framework-16-0-fastapi"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This addon provides the basis to smoothly integrate the <a class="reference external" href="https://fastapi.tiangolo.com/">FastAPI</a>
Expand Down
5 changes: 4 additions & 1 deletion fastapi/tests/test_fastapi_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def assert_exception_processed(
demo_app._get_app(), raise_server_exceptions=False
) as test_client, mock.patch.object(
self.env.cr.__class__, "rollback"
) as mock_rollback:
) as mock_rollback, mock.patch.object(
self.env.cr.__class__, "close"
) as mock_close:
response: Response = test_client.get(
"/demo/exception",
params={
Expand All @@ -56,6 +58,7 @@ def assert_exception_processed(
},
)
mock_rollback.assert_called_once()
mock_close.assert_called_once()
self.assertEqual(response.status_code, expected_status_code)
self.assertDictEqual(
response.json(),
Expand Down

0 comments on commit f40f84b

Please sign in to comment.