-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Module
auditlog
Describe the bug
Related fields with store=True have no value (False) after a create call on models where an auditlog.rule is defined for creation events.
This issue is not reproducible with pure computed fields or with non-stored related fields.
To Reproduce
Affected versions: 17.0, 18.0
Steps to reproduce the behavior:
- Create two simple models with a related field like so:
- Add an
auditlog.ruleon themodel.two, logging for creations - Create a
model.twoinstance and check the related field value:
Expected behavior
The related field should have the correct value after the create call:
(this screenshot was obtained with server-tools commit 51a4e9c, right before #3373 was merged, which introduced this issue)
Workaround
I've tried some things in the ThrowAwayCache class and this modified __exit__ method below seems to fix the issue described here, but it's really just a starting point and probably has some unintended side effects as i'm not familiar with Odoo cache handling. However, the current auditlog module tests seem to be passing with it:
def __exit__(self, exc_type, exc_val, exc_tb):
"""Restore the original cache wherever it was replaced."""
temp_cache = self._transaction.cache
for field, field_cache in temp_cache._data.items():
if field.related and field.store:
if field not in self._original_cache._data.keys():
self._original_cache._data[field] = field_cache
else:
self._original_cache._data[field].update(field_cache)
for env in self._transaction.envs:
env.cache = self._original_cache
self._transaction.cache = self._original_cache