summaryrefslogtreecommitdiff
path: root/odoo/fields.py
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2019-12-11 07:43:39 +0000
committerXavier Morel <xmo@odoo.com>2019-12-13 13:24:30 +0000
commitf3b41d3c28ca6ff3dfdb14c4aa2c9a20cee70ea4 (patch)
tree296e4e3204673c83340e857de527fb71a618c7a5 /odoo/fields.py
parent7281a7d9d58ba40e000f055a497b95f626134a94 (diff)
[IMP] core: error message on non-hashable from cache_key
Makes it way easier to realise that a cache access blew up because of a @depends_context('active_ids'), which returns a list, which is not hashable. closes odoo/odoo#41863 X-original-commit: 5d2ce1fb3f2f14c9274924d3f4052279671a0c3b Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
Diffstat (limited to 'odoo/fields.py')
-rw-r--r--odoo/fields.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/odoo/fields.py b/odoo/fields.py
index e6a6d1df1ee..7b3cf6e3a41 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -638,9 +638,8 @@ class Field(MetaField('DummyField', (object,), {})):
def cache_key(self, env):
""" Return the cache key corresponding to ``self.depends_context``. """
- get_context = env.context.get
- def get(key):
+ def get(key, get_context=env.context.get):
if key == 'company':
return env.company.id
elif key == 'uid':
@@ -648,7 +647,16 @@ class Field(MetaField('DummyField', (object,), {})):
elif key == 'active_test':
return get_context('active_test', self.context.get('active_test', True))
else:
- return get_context(key)
+ v = get_context(key)
+ try: hash(v)
+ except TypeError:
+ raise TypeError(
+ "Can only create cache keys from hashable values, "
+ "got non-hashable value {!r} at context key {!r} "
+ "(dependency of field {})".format(v, key, self)
+ ) from None # we don't need to chain the exception created 2 lines above
+ else:
+ return v
return tuple(get(key) for key in self.depends_context)