From a9088c2e717c51857f47097ce9a9f6071e1ff2ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Thu, 21 Dec 2023 16:33:47 +0100 Subject: [PATCH] Revert "[FIX] fastapi: close cursor after rollback" This reverts commit 8be7fbb0fda92b46e4913176185fb4e19ab319be. --- fastapi/error_handlers.py | 7 +------ fastapi/tests/test_fastapi_demo.py | 5 +---- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/fastapi/error_handlers.py b/fastapi/error_handlers.py index 2b3584b6..a7b4d9b2 100644 --- a/fastapi/error_handlers.py +++ b/fastapi/error_handlers.py @@ -23,15 +23,10 @@ def _rollback(request: Request, reason: str) -> None: - env = odoo_env_ctx.get() - cr = env.cr + cr = odoo_env_ctx.get().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( diff --git a/fastapi/tests/test_fastapi_demo.py b/fastapi/tests/test_fastapi_demo.py index 248a39fd..5cd9fef5 100644 --- a/fastapi/tests/test_fastapi_demo.py +++ b/fastapi/tests/test_fastapi_demo.py @@ -47,9 +47,7 @@ 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, mock.patch.object( - self.env.cr.__class__, "close" - ) as mock_close: + ) as mock_rollback: response: Response = test_client.get( "/demo/exception", params={ @@ -58,7 +56,6 @@ 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(),