[19.0][FIX] auditlog: flush pending recomputations before swapping the cache - #3718
Open
skanndar wants to merge 1 commit into
Open
[19.0][FIX] auditlog: flush pending recomputations before swapping the cache#3718skanndar wants to merge 1 commit into
skanndar wants to merge 1 commit into
Conversation
With a full-log rule on account.move, registering a payment leaves the payment's liquidity line with amount_residual, amount_residual_currency and reconciled NULL in the database. The outstanding-credits widget domain requires a non-NULL residual, so the payment is never proposed as an outstanding credit on the invoice. The old/new-values reads of the full log run inside ThrowAwayCache while records touched earlier in the transaction still have pending recomputations of stored computed fields. Tracing the transaction shows the context manager restores tocompute intact on exit, but after the swap/read/restore cycle those pending recomputations are consumed by the subsequent write and flush without ever being persisted: they leave tocompute, never appear in field_dirty, and the columns stay NULL. Flushing everything still pending before setting the cache aside removes the hazard: with nothing pending, there is nothing the swap can lose. Fixes OCA#3635
skanndar
force-pushed
the
19.0-fix-auditlog-flush-before-throwawaycache
branch
from
August 27, 2026 19:26
dbc92bc to
1977e87
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3635.
With a full-log rule on
account.move, registering a payment leaves the payment's liquidity move line withamount_residual/amount_residual_currency/reconciledset to NULL in the database. The outstanding-credits widget domain (_compute_payments_widget_to_reconcile_info) ends in'|', ('amount_residual', '!=', 0.0), ('amount_residual_currency', '!=', 0.0); with both columns NULL neither leg matches, so the payment is never proposed as an outstanding credit on the invoice. We hit this in production and reproduced it on a virgin database with onlyaccount(demo data) +auditlog.What the trace shows (instrumenting the transaction state around
ThrowAwayCacheand peeking at the database at each step):write_full()performs the old-values read insideThrowAwayCache, the payment's move lines still have pending recomputations of their stored computed fields intransaction.tocompute.tocomputeintact on exit. But after this swap/read/restore cycle, those pending recomputations are consumed during the subsequentwrite.origin+flush_recordset()without being persisted: they leavetocompute, never appear infield_dirty, and the database columns remain NULL.With a Fast log rule (no
ThrowAwayCache) the very same flow marks the lines dirty and they reach the database.The fix makes the swap safe by flushing everything still pending right before setting the cache aside, in
ThrowAwayCache.__enter__: with nothing pending, there is nothing the swap can lose, and the values read for the log are read after the pending state is persisted.env.flush_all()is broader than the strict minimum, but this is a correctness fix and the flushed work is work the transaction had to do anyway.Includes a regression test (post an invoice → register a payment with a full-log rule on
account.move→ assert the payment lines' stored computed columns are not NULL). It fails on current 19.0 withAssertionError: unexpectedly None : line ...: amount_residual is NULLand passes with the fix; the wholeauditlog+test_auditlogsuite is green (58 tests).May also be related to #3638 (same disposable-cache family); not verified.