[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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user