Skip to content

Commit

Permalink
fixup! [FIX] fastapi: close cursor after rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
lmignon committed Dec 21, 2023
1 parent d85bf2a commit 06227cd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 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
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
18 changes: 18 additions & 0 deletions fastapi_auth_jwt_demo/tests/test_fastapi_auth_jwt_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import time
from unittest import mock

import jwt

Expand Down Expand Up @@ -31,6 +32,23 @@ def _get_token(self, aud=None, email=None):
)
return "Bearer " + access_token

def url_open(
self,
url,
data=None,
files=None,
timeout=12,
headers=None,
allow_redirects=True,
head=False,
):
# override to prevent the closing og the database cursor in case of exception
# in the fastapi endpoint execution
with mock.patch.object(type(self.env.cr), "close"):
return super().url_open(
url, data, files, timeout, headers, allow_redirects, head
)

def test_whoami(self):
"""A end-to-end test with positive authentication and partner retrieval."""
partner = self.env["res.users"].search([("email", "!=", False)])[0]
Expand Down

0 comments on commit 06227cd

Please sign in to comment.