[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 <rco@odoo.com>
This commit is contained in:
Thomas Lefebvre (thle)
2024-02-13 09:07:38 +00:00
parent a24f15d628
commit 176f5ec4a2
+2
View File
@@ -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