summaryrefslogtreecommitdiff
path: root/odoo/fields.py
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2020-09-17 12:22:22 +0000
committerRaphael Collet <rco@odoo.com>2020-09-21 12:40:19 +0000
commitaebe9a76c9b35e84eda1f46bec3ef6da152b1539 (patch)
tree43f10cb1fecc98e041f455b6fbc7c0b9e8ca030a /odoo/fields.py
parentdc591641f3bf8dee50f172134ffd686edc571bd3 (diff)
[FIX] core: always evaluate field.depends upon setup
This is necessary when a field's dependencies are given by a callable. This functionality was broken with the support for an explicit parameter `depends` in the fields' definition, because the implementation could not distinguish between the field parameter `depends` and the `depends` evaluated from compute functions. The fix consists in storing the field parameter `depends` into `field._depends`, and the result of the setup into `field.depends`. closes odoo/odoo#58127 X-original-commit: d4d7925d69c9a37f099ddd3a8929004f17e162eb Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo/fields.py')
-rw-r--r--odoo/fields.py28
1 files changed, 20 insertions, 8 deletions
diff --git a/odoo/fields.py b/odoo/fields.py
index e6325fe59d5..effdec15c78 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -222,8 +222,8 @@ class Field(MetaField('DummyField', (object,), {})):
index = False # whether the field is indexed in database
manual = False # whether the field is a custom field
copy = True # whether the field is copied over by BaseModel.copy()
- depends = None # collection of field dependencies
- depends_context = None # collection of context key dependencies
+ _depends = None # collection of field dependencies
+ _depends_context = None # collection of context key dependencies
recursive = False # whether self depends on itself
compute = None # compute(recs) computes field on recs
compute_sudo = False # whether field should be recomputed as superuser
@@ -344,8 +344,13 @@ class Field(MetaField('DummyField', (object,), {})):
if attrs.get('translate'):
# by default, translatable fields are context-dependent
attrs['depends_context'] = attrs.get('depends_context', ()) + ('lang',)
+
+ # parameters 'depends' and 'depends_context' are stored in attributes
+ # '_depends' and '_depends_context', respectively
if 'depends' in attrs:
- attrs['depends'] = tuple(attrs['depends'])
+ attrs['_depends'] = tuple(attrs.pop('depends'))
+ if 'depends_context' in attrs:
+ attrs['_depends_context'] = tuple(attrs.pop('depends_context'))
return attrs
@@ -407,7 +412,10 @@ class Field(MetaField('DummyField', (object,), {})):
def _setup_regular_full(self, model):
""" Determine the dependencies and inverse field(s) of ``self``. """
- if self.depends is not None:
+ if self._depends is not None:
+ # the parameter 'depends' has priority over 'depends' on compute
+ self.depends = self._depends
+ self.depends_context = self._depends_context or ()
return
# determine the functions implementing self.compute
@@ -420,7 +428,7 @@ class Field(MetaField('DummyField', (object,), {})):
# collect depends and depends_context
depends = []
- depends_context = list(self.depends_context or ())
+ depends_context = list(self._depends_context or ())
for func in funcs:
deps = getattr(func, '_depends', ())
depends.extend(deps(model) if callable(deps) else deps)
@@ -460,7 +468,9 @@ class Field(MetaField('DummyField', (object,), {})):
raise TypeError("Type of related field %s is inconsistent with %s" % (self, field))
# determine dependencies, compute, inverse, and search
- if self.depends is None:
+ if self._depends is not None:
+ self.depends = self._depends
+ else:
self.depends = ('.'.join(self.related),)
self.compute = self._compute_related
if self.inherited or not (self.readonly or field.readonly):
@@ -486,7 +496,9 @@ class Field(MetaField('DummyField', (object,), {})):
self.required = True
self._modules.update(field._modules)
- if field.depends_context:
+ if self._depends_context is not None:
+ self.depends_context = self._depends_context
+ else:
self.depends_context = field.depends_context
def traverse_related(self, record):
@@ -1883,7 +1895,7 @@ class Binary(Field):
type = 'binary'
prefetch = False # not prefetched by default
- depends_context = ('bin_size',) # depends on context (content or size)
+ _depends_context = ('bin_size',) # depends on context (content or size)
attachment = True # whether value is stored in attachment
@property