[FIX] core: fix create/write on binary fields

When invoking create() or write() with a binary field, the cache of the
field was incorrect if bin_size=True was in context.  Force context with
bin_size=False when putting a binary value in cache.  It is particularly
important to have coherent values in the cache for `web_save`.

Also, because an environment with bin_size=False won't return the same
context cache key as one with bin_size=None, it leads to have a cache
inconstistency when we write with bin_size=False.  Change Environment
method cache_key() to return the same cache key when bin_size is absent,
bin_size=None or bin_size=False.

Tests on binary fields have been updated to not rely on flush and
invalidate.  We also created specific tests for write() on binary
fields.

Part-of: odoo/odoo#160708
This commit is contained in:
Rémy Voet (ryv)
2024-04-26 17:17:52 +00:00
committed by Raphael Collet
parent a0bf434960
commit 87a1ebb338
5 changed files with 83 additions and 17 deletions
+2
View File
@@ -815,6 +815,8 @@ class Environment(Mapping):
return get_context('lang') or None
elif key == 'active_test':
return get_context('active_test', field.context.get('active_test', True))
elif key.startswith('bin_size'):
return bool(get_context(key))
else:
val = get_context(key)
if type(val) is list: