Skip to content

Commit 7f5517d

Browse files
gonzalesedwin1123kneckinator
authored andcommitted
fix(fastapi): inherit from SerializationFailure for Odoo 19 retrying (#53)
Odoo 19's retrying() uses isinstance checks against PG_CONCURRENCY_EXCEPTIONS_TO_RETRY instead of pgcode-based checks. FakeConcurrentUpdateError inherited from OperationalError (a sibling of SerializationFailure), so isinstance returned False and the exception was re-raised instead of retried.
1 parent fc4ce29 commit 7f5517d

2 files changed

Lines changed: 2 additions & 4 deletions

File tree

fastapi/routers/demo_router.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Annotated
99

1010
from psycopg2 import errorcodes
11-
from psycopg2.errors import OperationalError
11+
from psycopg2.errors import SerializationFailure
1212

1313
from odoo.api import Environment
1414
from odoo.exceptions import AccessError, MissingError, UserError, ValidationError
@@ -138,7 +138,7 @@ async def retrying_post(
138138
return JSONResponse(content={"retries": tryno, "file": file.decode("utf-8")})
139139

140140

141-
class FakeConcurrentUpdateError(OperationalError):
141+
class FakeConcurrentUpdateError(SerializationFailure):
142142
@property
143143
def pgcode(self):
144144
return errorcodes.SERIALIZATION_FAILURE

fastapi/tests/test_fastapi.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ def test_lang(self):
135135
self._assert_expected_lang("fr-FR,en;q=0.7,en-GB;q=0.3", b'"fr_BE"')
136136
self._assert_expected_lang("fr-FR;q=0.1,en;q=1.0,en-GB;q=0.8", b'"en_US"')
137137

138-
@unittest.skip("Odoo 19: FastAPI retrying mechanism returns 500 in test mode (#53)")
139138
def test_retrying(self):
140139
"""Test that the retrying mechanism is working as expected with the
141140
FastAPI endpoints.
@@ -146,7 +145,6 @@ def test_retrying(self):
146145
self.assertEqual(response.status_code, 200)
147146
self.assertEqual(int(response.content), nbr_retries)
148147

149-
@unittest.skip("Odoo 19: FastAPI retrying mechanism returns 500 in test mode (#53)")
150148
def test_retrying_post(self):
151149
"""Test that the retrying mechanism is working as expected with the
152150
FastAPI endpoints in case of POST request with a file.

0 commit comments

Comments
 (0)