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)