[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>
This commit is contained in:
+11
-3
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user