From f3b41d3c28ca6ff3dfdb14c4aa2c9a20cee70ea4 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 11 Dec 2019 07:43:39 +0000 Subject: [PATCH] [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) --- odoo/fields.py | 14 +++++++++++--- 1 file 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)