Skip to content

[19.0][FWP] base_exception: forward port missing commits from 18.0 - #3879

Open
lef-adhoc wants to merge 10 commits into
OCA:19.0from
adhoc-dev:19.0-t-74050-lef
Open

lef-adhoc wants to merge 10 commits into
OCA:19.0from
adhoc-dev:19.0-t-74050-lef

Conversation

@lef-adhoc

@lef-adhoc lef-adhoc commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Forward port of the base_exception commits that are in 18.0 and missing in 19.0.

Why

The exception mechanism was refactored in 18.0 (#3590) and fixed several times afterwards. 19.0 was migrated before that work and still carries the old mechanism, so any module that builds on base_exception behaves differently depending on the version, and the fixes merged in 18.0 are simply not available in 19.0.

Supersedes #3729

This PR includes the six commits of #3729 unchanged (same authors), rebased on the current 19.0, plus its two 19.0 adaptations, plus the two commits that were merged in 18.0 after that PR was opened:

@sergio-teruel, the intention is not to take over your work: #3729 has been open since September and two more fixes landed in 18.0 in the meantime, so this collects everything in a single mergeable branch with your commits untouched. Happy to close this one instead if you prefer to update #3729.

Not forward ported

  • [REF] base_exception: use FakeModuleLoader in setUp, not setUpClass — obsolete here: the 19.0 migration dropped odoo_test_helper and sets the test models up with add_to_registry.

Follow up

sale_exception has the matching chain of commits missing in 19.0 and depends on this one: OCA/sale-workflow#4828.

Every commit was cherry-picked without conflicts; pre-commit passes on the branch.

grindtildeath and others added 10 commits November 24, 2026 13:24
This aims to solve issues when modules not depending on whatever
implementation of base_exception, override the same function that
triggers the detection of exceptions.

Before this commit, any changes done in such overrides could end
up being committed to the database if the MRO did execute such
function before the function implementing base_exception that avoids
to call super in case an exception is detected. (eg sale.order.
action_confirm in sale_exception)

With this commit, in case there is any newly detected exception,
or a record with exception that is not ignored, or a blocking
exception linked to a record, exception changes will be committed
in DB while a specific Exception type will be raised to rollback
any changes done in the ongoing transaction. Such an exception
will be handled in the UI to refresh the exception_ids field
so that the user knows why the action was not completed.
With the previous change raising an exception to rollback a
transaction, the function `_popup_exceptions` could not be called
anymore while the error was raised.

Instead, we provide now a hook `_must_popup_exception` that can be
redefined by model and will be called when `action_popup_exception`
is called by the webclient, to smoothly refresh the page and
display the popup exception wizard.
Simplify the JS layer by leveraging client actions.

Return a custom client action whenever the BaseExceptionError
is catched on RPC call and handle everything through the call
to action_popup_exceptions:
- In case exception should not pop up, return a soft reload client
action instead of handling the refresh manually in JS
- In case exception should pop up, return the wizard action, but
do a soft reload first to display the exception_ids block before
execution the wizard opening action.
Make test decorator available for import in other modules

Avoid using new env for unrelated tests
detect_exceptions() stores the exceptions in a separate transaction (a new
cursor/connection) so that they are kept when the ongoing transaction is
rolled back. When the registry is not ready yet (module installation or
update), the ongoing transaction holds exclusive locks on the tables it has
just modified (ALTER TABLE ...). The call to
_must_raise_exception_after_detection() made inside that new transaction then
reads the model records, and the query waits for those locks forever: the
only thread able to release them is the one waiting for them.

This happens as soon as demo data confirming a sale order is loaded during a
database initialisation with sale_exception installed (e.g. the sale_stock
demo data), making the whole database initialisation hang.

Use the current cursor in that case, as already done when running tests.
…transaction

detect_exceptions() opens a second, genuinely independent DB connection
(self.env.registry.cursor()) to write exception flags so they survive a
rollback of the ongoing transaction. It then re-derived main_records
through that same second connection (self.with_env(new_env)), which
crashes with MissingError whenever _get_main_records() has to read a
field on records created earlier in the SAME ongoing transaction and not
yet committed (e.g. sale.order.line._get_main_records() reading order_id
right after the line was created by write()).

Typical trigger: adding a product to an already confirmed sale order.
sale_exception.write() re-runs detect_exceptions() on order_line whenever
order_line changes on a confirmed order; the new line only exists in the
ongoing transaction, so the second connection can't see it yet.

Resolve main_records once through the original (main) cursor, which does
see the just-created records, and only rebind that already-resolved
recordset to the new environment for the exception_ids check.
Odoo 19.0 dropped 'decorator' from its core requirements.txt (present in18.0).
base_exception's tests use it directly (via the decorator package, not through odoo_test_helper as in 18.0),
so CI fails with ModuleNotFoundError: No module named 'decorator' when running the forward-ported test suite.
Odoo 19.0 renamed Registry.enter_test_mode(cr)/leave_test_mode() to TransactionCase.registry_enter_test_mode()/registry_leave_test_mode(),
with automatic cleanup registration. test_rollback_main_transaction (forward-ported from 18.0 in an earlier commit) still used the old API,
failing with AttributeError: 'Registry' object has no attribute 'enter_test_mode'.
The dialog can confirm the record (ticking "Ignore Exceptions" calls
action_confirm on it), but closing it only closes the dialog: the view
underneath keeps showing the record as it was before, so the user sees a
quotation that is already a sales order.

Reload once the dialog closes.
Add _must_rollback_on_exception(), true by default: it is false for the
main records listed in the base_exception_no_rollback context
({model: ids}), and then the exceptions are stored in the ongoing
transaction and detect_exceptions() does not raise.

Callers that already wrote on those records in the transaction cannot
use the second cursor: it waits forever on the row lock held by the
ongoing transaction.
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @hparfr, @sebastienbeau,
some modules you are maintaining are being modified, check this out!

lef-adhoc added a commit to adhoc-dev/sale-workflow that referenced this pull request Nov 24, 2026
Registry.enter_test_mode() is the 18.0 API. In 19.0 the TransactionCase
helper registry_enter_test_mode() takes its place and registers the cleanup
itself, so the test errored with AttributeError. Same adaptation already
applied to base_exception in OCA/server-tools#3879.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants