Skip to content

fix(spp_audit): tighten audit context flags and audit nested writes - #611

Open
gonzalesedwin1123 wants to merge 6 commits into
19.0from
fix-audit-context-flags
Open

gonzalesedwin1123 wants to merge 6 commits into
19.0from
fix-audit-context-flags

Conversation

@gonzalesedwin1123

@gonzalesedwin1123 gonzalesedwin1123 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Stacked on #605: until that merges, the first two commits shown here (9e8d83cb, b5e5d5ad) belong to it. This PR is the three commits after them.

Summary

  • audit_disable is honoured only when server-side code sets it to the AUDIT_DISABLE marker exported from spp_audit.tools:

    from odoo.addons.spp_audit.tools import AUDIT_DISABLE
    
    records.with_context(audit_disable=AUDIT_DISABLE).write(vals)

    A plain value such as True is ignored and the operation is audited.

  • A write made inside an audited write is audited when it touches other records, for example a child record updated through its parent's one2many field. Only the records already being audited by the enclosing write are skipped, so the same change is not logged twice. The audit_in_progress context key is no longer read; the records being audited are tracked on the cursor.

  • spp_audit to 19.0.2.0.4 with a HISTORY entry. No schema or data change, so no migration.

Behaviour changes to note

Test plan

  • ./spp t spp_audit: 0 failed, 0 errors of 64 tests (49 on the base branch + 15 new)
  • Bulk write loop timing unchanged: about 2.7 s per 1,000 single-record partner writes, flat across batches
  • pre-commit on the changed files
  • README.rst / static/description/index.html regenerated from CI's output
  • Dependent modules' suites in CI

The audit backend methods and the rule's logging entry points are called
only from server-side code. Mark them @api.private and cover it with
tests. Server-side callers are unaffected.
… code

audit_disable and audit_in_progress are now matched by identity against
marker objects defined in spp_audit, instead of by truthiness. Trusted
flows pass spp_audit.tools.AUDIT_DISABLE; a plain value is ignored and the
operation is audited.
The in-progress guard covered every model and record for the duration of
the original write, so a nested write to another record was not audited.
Track the records being audited on the cursor and skip a nested write for
those records only.
Check the in-progress records are released when the write fails without
relying on assertRaises, and that copying a context keeps the marker.
@gonzalesedwin1123
gonzalesedwin1123 changed the base branch from fix-audit-private-methods to 19.0 November 24, 2026 16:00
@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.35%. Comparing base (a71e8f0) to head (afa37cc).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             19.0     #611      +/-   ##
==========================================
+ Coverage   77.17%   77.35%   +0.17%     
==========================================
  Files         727      751      +24     
  Lines       47006    48916    +1910     
==========================================
+ Hits        36276    37838    +1562     
- Misses      10730    11078     +348     
Flag Coverage Δ
spp_audit 74.62% <100.00%> (?)
spp_base_common 91.07% <ø> (ø)
spp_cel_event 85.34% <ø> (?)
spp_claim_169 58.18% <ø> (ø)
spp_dci_demo 94.28% <ø> (ø)
spp_dci_indicators 96.23% <ø> (?)
spp_drims 85.49% <ø> (ø)
spp_drims_sl_demo 68.33% <ø> (-0.15%) ⬇️
spp_farmer_registry 88.46% <ø> (ø)
spp_farmer_registry_cr 61.24% <ø> (ø)
spp_farmer_registry_demo 63.32% <ø> (-0.07%) ⬇️
spp_mis_demo_v2 70.41% <ø> (ø)
spp_programs 67.58% <ø> (ø)
spp_registry 89.00% <ø> (ø)
spp_security 69.56% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
spp_audit/models/spp_audit_backend.py 69.50% <100.00%> (ø)
spp_audit/models/spp_audit_rule.py 79.13% <100.00%> (ø)
spp_audit/tools/__init__.py 100.00% <100.00%> (ø)
spp_audit/tools/decorator.py 100.00% <100.00%> (ø)

... and 22 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gonzalesedwin1123
gonzalesedwin1123 marked this pull request as ready for review November 24, 2026 16:27
@gonzalesedwin1123
gonzalesedwin1123 requested review from jeremi and kneckinator and removed request for kneckinator November 24, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant