server-tools icon indicating copy to clipboard operation
server-tools copied to clipboard

[16.0] auditlog: Full Log Mode Does Not Log Field Changes Correctly

Open BT-pgaiser opened this issue 1 month ago • 2 comments

Module

auditlog (confirmed for at least v16)

Describe the bug

When trying to log a write call for a record for which a rule with full log mode exists, the auditlog code compares old vs. new field values to determine whether to create a log line for that change. Due to the changes in PR#3371, a new field value might erroneously be evaluated the same as the old value, which means no log line is created even though there is a change. The issue persists even with the fix from PR#3409. The problem seems to be that the read() call effectively reads the old values from the database.

Possible Fix

I was able to observe that the issue is solved when the pending data changes are flushed to the DB after the actual write was executed. For example, this can be achieved by adding the following line before the read() call to get the new_values:

self.env.flush_all()

Alternatively, the issue also seems to be fixed when the ThrowAwayCache context manager is removed when obtaining new_values.

To Reproduce

Affected versions: v16

Steps to reproduce the behavior:

  1. Create a log rule with full log mode.
  2. In the UI go to a form view of a record and change a field value.
  3. Inspect the log lines of the created log entry. The change is not logged properly.

Expected behavior The change should be logged properly, including old and new field values.

BT-pgaiser avatar Nov 11 '25 09:11 BT-pgaiser

Thanks for the report. Probably a duplicate of https://github.com/OCA/server-tools/issues/3420. In that case, I was thinking of trying to address the issue with a flush (maybe only of the updated recordset). Would you be able to propose a PR for this, with a reproducing test?

StefanRijnhart avatar Nov 15 '25 11:11 StefanRijnhart

OK, I am going to provide a patch for this issue. I am astounded that the existing test suite didn't catch it.

BT-pgaiser avatar Nov 17 '25 09:11 BT-pgaiser