From 176f5ec4a2af85315781f0fb19841d345f1fa94b Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Mon, 12 Feb 2024 13:54:28 +0100 Subject: [PATCH] [FIX] api: assert cr is a cursor when creating a new environment `Environment.__new__` expects a Cursor. Ensure developers pass a Cursor and not another kind of unexpected object. Passing another object with the same attributes would work during the creation of the new environment, but then would fail later, when using the created environment with the wrong `cr` attribute, with a less comprehensive error. Task-3796479 closes odoo/odoo#80644 Signed-off-by: Raphael Collet --- odoo/api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/odoo/api.py b/odoo/api.py index 6ad93648155..507c7153b7f 100644 --- a/odoo/api.py +++ b/odoo/api.py @@ -508,6 +508,7 @@ class Environment(Mapping): return env # otherwise create environment, and add it in the set + assert isinstance(cr, BaseCursor) self = object.__new__(cls) self.cr, self.uid, self.context, self.su = self.args = (cr, uid, frozendict(context), su) self.uid_origin = uid_origin @@ -1361,3 +1362,4 @@ class Starred: # keep those imports here in order to handle cyclic dependencies correctly from odoo import SUPERUSER_ID from odoo.modules.registry import Registry +from .sql_db import BaseCursor