Skip to content

fix(spp_hide_menus_base): make the menu-hiding pass best-effort on database errors (#526) - #532

Open
gonzalesedwin1123 wants to merge 3 commits into
19.0from
fix-526-hide-menus-register-hook
Open

gonzalesedwin1123 wants to merge 3 commits into
19.0from
fix-526-hide-menus-register-hook

Conversation

@gonzalesedwin1123

Copy link
Copy Markdown
Member

Fixes #526. Sibling of #525 (#383), scoped to the hook that actually runs on the registry-load path.

Problem

spp_hide_menus_base runs hide_menus() from ir.module.module._register_hook, i.e. at the end of every registry load (startup, install, upgrade, every worker reload). Inside it calls search, env.ref_xmlid_lookup, and spp.hide.menu create/write, with only a ValueError guard around the lookup. Any psycopg2.Error propagated out of _register_hook and aborted the registry load. On a cursor already poisoned by an unrelated failure that meant every restart died with InFailedSqlTransaction until the database was quarantined — the shape of the 2026-07-30 preprod incident (odoo-job-worker#22).

Fix

hide_menus() is now the guarded entry point used by both next() and _register_hook():

spp_hide_menus_base 19.0.2.1.0 → 19.0.2.1.1 with a HISTORY fragment. README/index.html left for CI's pinned generator.

Tests (tests/test_register_hook_guard.py, 4 new)

  1. missing menu xmlid: hook neither raises nor warns;
  2. SQL failure inside the xmlid lookup, driven through _register_hook(): returns, warns, transaction still usable, and the pass is atomic (a menu hidden earlier in the same pass is rolled back); order-independent via the first/last rows of ir.module.module.search([]);
  3. cursor already aborted before _register_hook(): no raise, warning logged;
  4. caller's pending ORM write on a poisoned cursor: hide_menus() raises InFailedSqlTransaction and logs nothing (the guard does not swallow it).

Pre-fix: tests 2 and 3 error with UndefinedTable / InFailedSqlTransaction out of _register_hook. Post-fix: 0 failed, 0 error(s) of 29 tests. All pre-commit hooks pass on the changed files.

Out of scope: #410 (re-snapshot in hide_menu()), same path, separate issue.

…tabase errors

hide_menus() runs from ir.module.module._register_hook at the end of
every registry load. A psycopg2.Error escaping it aborted the registry
load, so on a poisoned cursor every restart failed until the database
was repaired by hand. The pass now flushes the caller's pending writes,
runs in its own savepoint, and logs and skips any psycopg2.Error;
a missing menu xmlid uses raise_if_not_found=False.

Fixes #526
@codecov

codecov Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.83333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.05%. Comparing base (1a3c591) to head (90b4665).

Files with missing lines Patch % Lines
spp_hide_menus_base/models/ir_module_module.py 95.83% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             19.0     #532      +/-   ##
==========================================
+ Coverage   76.91%   77.05%   +0.14%     
==========================================
  Files         704      727      +23     
  Lines       45774    47171    +1397     
==========================================
+ Hits        35205    36346    +1141     
- Misses      10569    10825     +256     
Flag Coverage Δ
spp_analytics 93.25% <ø> (ø)
spp_api_v2_change_request 73.37% <ø> (ø)
spp_api_v2_cycles 71.03% <ø> (ø)
spp_api_v2_data 77.77% <ø> (ø)
spp_api_v2_entitlements 70.23% <ø> (ø)
spp_api_v2_gis 74.60% <ø> (ø)
spp_api_v2_programs 92.22% <ø> (ø)
spp_approval 50.85% <ø> (ø)
spp_area 80.16% <ø> (?)
spp_area_hdx 81.60% <ø> (?)
spp_base_common 91.07% <ø> (ø)
spp_case_cel 89.50% <ø> (ø)
spp_case_demo 94.82% <ø> (ø)
spp_case_entitlements 100.00% <ø> (ø)
spp_case_programs 100.00% <ø> (ø)
spp_hide_menus_base 95.65% <95.83%> (?)
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_hide_menus_base/models/ir_module_module.py 92.50% <95.83%> (ø)

... 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.

- test_02 gains a control run proving the catalog entry hides the menu
  before the failing pass, so the rollback assertions are falsifiable
- warning assertion matches the message text, not the logger name
- HISTORY attributes the incident to odoo-job-worker#22, which #383
  had first pinned on the menu-icon hook
- docstring states why only psycopg2.Error is caught, why the pass is
  all-or-nothing, and that retryable errors are swallowed on purpose
- log line no longer claims the registry load continues on an already
  aborted transaction
- flatten the extracted loop; explicit psycopg2.errors import
@gonzalesedwin1123
gonzalesedwin1123 marked this pull request as ready for review September 21, 2026 03:24
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.

spp_hide_menus_base: hide_menus() runs env.ref from _register_hook with no database-error guard, so a poisoned cursor aborts every registry load

1 participant