From 1a2a5cf7793dc8aeb97cfac8b0b90944424d5414 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Thu, 21 Dec 2023 11:32:15 +0100 Subject: [PATCH] fixup! [FIX] fastapi: close cursor after rollback --- fastapi/error_handlers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fastapi/error_handlers.py b/fastapi/error_handlers.py index 31941d36c..2b3584b6a 100644 --- a/fastapi/error_handlers.py +++ b/fastapi/error_handlers.py @@ -23,13 +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. - cr.close() + if not (env.registry.in_test_mode()): + cr.close() async def _odoo_user_error_handler(