diff options
| author | Raphael Collet <rco@odoo.com> | 2018-01-18 12:15:15 +0100 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2018-01-23 16:41:45 +0100 |
| commit | f1d60d2e528284c4d4401d40e362f1b45ac32211 (patch) | |
| tree | 572031ea4a6997928ada1f5a519fae590798e405 /odoo/api.py | |
| parent | 74801feb0cfd26d09e767878c18dfffaa220ab51 (diff) | |
[IMP] api: make the implementation of field protection more robust
Diffstat (limited to 'odoo/api.py')
| -rw-r--r-- | odoo/api.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/odoo/api.py b/odoo/api.py index e9657b798c0..e0ba72a7e51 100644 --- a/odoo/api.py +++ b/odoo/api.py @@ -55,7 +55,7 @@ from weakref import WeakSet from decorator import decorator from werkzeug.local import Local, release_local -from odoo.tools import frozendict, classproperty +from odoo.tools import frozendict, classproperty, StackMap _logger = logging.getLogger(__name__) @@ -741,7 +741,7 @@ class Environment(Mapping): self.cr, self.uid, self.context = self.args = (cr, uid, frozendict(context)) self.registry = Registry(cr.dbname) self.cache = envs.cache - self._protected = defaultdict(frozenset) # {field: ids, ...} + self._protected = StackMap() # {field: ids, ...} self.dirty = defaultdict(set) # {record: set(field_name), ...} self.all = envs envs.add(self) @@ -861,14 +861,15 @@ class Environment(Mapping): @contextmanager def protecting(self, fields, records): """ Prevent the invalidation or recomputation of ``fields`` on ``records``. """ - saved = {} + protected = self._protected try: + protected.pushmap() for field in fields: - ids = saved[field] = self._protected[field] - self._protected[field] = ids.union(records._ids) + ids = protected.get(field, frozenset()) + protected[field] = ids.union(records._ids) yield finally: - self._protected.update(saved) + protected.popmap() def field_todo(self, field): """ Return a recordset with all records to recompute for ``field``. """ |
