Skip to content

[20.0][MIG] base_exception: Migration to 20.0 - #3800

Open
astirpe wants to merge 91 commits into
OCA:20.0from
astirpe:20_mig_base_exception
Open

astirpe wants to merge 91 commits into
OCA:20.0from
astirpe:20_mig_base_exception

Conversation

@astirpe

@astirpe astirpe commented Oct 22, 2026

Copy link
Copy Markdown
Member

No description provided.

mourad-ehm and others added 30 commits October 22, 2026 07:05
…lled by constraint methods

'detect_exception' can be called on an empty recordset.
- Show menu only to Exception Rule Managers
- Use sequence and active widgets on tree view
- Updated form to use sheet
[IMP] Computed exception descriptions field, to display better help messages

[IMP] Exceptions shouldn't be copied
By default exceptions can be ignored by the click of a button.
Users begin human they will just click that button what ever
the internal rules.

So this PR adds the option to set specific exceptions as blocking.

When exceptions are detected if one of them is blocking, the user
will not be able to ignore them.
use odoo-test-helper
split test so one test do one thing
This method is used by other modules that depend on 'base_exception'.
@astirpe

astirpe commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

@matiasperalta1 yes, thanks you!

I included #3734 in this migration. It cannot be ported alone: it changes code added by #3590, and #3723 and #3725 fix that same code. None of these were ever ported to 19.0. So I included those commits as well.

Also done the following:

  • Adapt the tests to 20.0. The decorator package is no longer installed with Odoo 20.0, so the test helpers now use functools. This also fixes [18.0] base_exception: swallow_base_exception_error never runs the decorated test #3784: the decorated tests now really run. registry.enter_test_mode() was replaced by registry_test_mode().
  • Keep sudo when the exceptions are stored in the new cursor. Without it, a detection run in sudo by a user without write access (for example from the portal) raised AccessError. I added a test for it. I’ll also propose this fix on 18.0.
  • Remove the credits of the 18.0 migration and update the README, as the migration guide asks.

I left #3741 out because it is not merged in 18.0 yet.

Closing the exception dialog with one of its buttons (Cancel, or Confirm,
which returns an act_window_close action) showed "Oops! Something went
wrong" (Component is destroyed).

In 20.0, the action plugin waits for onClose before it clears the dialog.
The soft_reload done in onClose closes all the dialogs, and this dialog is
still open, so onClose runs a second time. The second reload restores the
same form view while the first one is still loading it.

Closing the dialog with its X button is not affected: the dialog plugin
ignores the second close.

Reload only once.

Reported in OCA/sale-workflow#4681 (comment)

Co-authored-by: Franco Leyes <[email protected]>
@oca-cla-bot

oca-cla-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

The following commit authors need to sign the Contributor License Agreement:

CLA not signed

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

astirpe commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

@matiasperalta1 I also included #3741 now that it is merged in 18.0. Thanks!

@Expert-Odoo Expert-Odoo left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review and tested on 20.0, 17 tests pass. The _must_rollback_on_exception opt-out reads well and is covered by the new tests. LGTM.

@baselogica-ar

Copy link
Copy Markdown

Thanks for the migration. We found a hang with it on 20.0 (this PR at cf187a4, with sale_exception from OCA/sale-workflow#4681 at a1d420a).

Steps

  1. Run the server without --test-enable and install sale_management and sale_exception.
  2. Create an exception rule on Sales Order, "By domain": [('client_order_ref', '=', False)].
  3. Send a quotation that requires a signature and sign it from the portal.

Result
The request to /my/orders/<id>/accept never returns: after 3 minutes it was still waiting, and we terminated both backends. In pg_stat_activity, the request's transaction is idle in transaction, and a second connection waits on Lock / transactionid in UPDATE "sale_order" SET "main_exception_id" = ..., "write_date" = .... PostgreSQL does not detect it, because the request waits in Python, not on a lock.

Cause
portal_quote_accept (sale/controllers/portal.py) writes the signature on the order and flushes before _validate_order() → action_confirm(), so the request's transaction holds the row lock on sale_order. detect_exceptions() then writes exception_ids on the same order through self.env.registry.cursor() (L111-L124): the new connection waits for the request's transaction, which waits for the with block to end.

Any flow that writes the record and confirms it in the same transaction can hit this; it is the runtime counterpart of #3723. The tests cannot catch it, since with test_enable the current cursor is used (L100-L102). The same code is in 18.0 since #3590; we have not tested it there.

sergio-teruel and others added 3 commits November 10, 2026 06:53
…he rows

Exceptions are written through an independent connection so they survive a rollback of the ongoing transaction. When the ongoing transaction has already written the same rows (e.g. a confirmed sale order line edited and flushed earlier in the request), the independent connection waits for its lock while the ongoing transaction waits in Python for the independent one to finish. PostgreSQL cannot detect that deadlock, so the request hung until the worker was killed, and every other request touching the same records piled up behind it.

The independent transaction now waits for row locks at most `_get_exception_lock_timeout()` milliseconds. When that expires, the exceptions are written in the ongoing transaction, and written again in a new transaction if the ongoing one is rolled back (as it is when the exception is raised to the user), once its locks are released, so the exception popup still finds them.

The logic lives in `_write_exceptions_independently()` so modules writing exceptions through their own independent connection, like sale_exception for order lines, can reuse it.

(cherry picked from commit 0619316)
…oing transaction

The independent connection cannot see records created by the ongoing transaction, e.g. a line added to a confirmed sale order, so writing their exceptions through it raises `MissingError` and the user got that error instead of the exception popup.

`_write_exceptions_independently()` now handles `MissingError` like a lock timeout: the exceptions are written in the ongoing transaction, so they are detected and raised, and written again after a rollback, skipping the records that no longer exist.

(cherry picked from commit 398df8e)
The postrollback hook must not raise, as an error there would break
closing the rolled back cursor: the broad except is on purpose. Mark it
for BLE001, which the 20.0 ruff configuration enables.
@astirpe

astirpe commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

@baselogica-ar you are right, thank you! Those are issues affecting version 18.0 as well.
I forward-ported #3739 from 18.0, it fixes the hang on base_exception 20.0.
For sale_exception I also forward-ported #4600 from 18.0 to fix the hang on portal signature when an exception rule matches.
Could you check if it's ok now?

@matiasgibbons

Copy link
Copy Markdown

Tested on a 20.0 instance with the Argentinian localization (l10n_ar + ADHOC modules), both on a database with our production modules installed and on a fresh database with demo data (as in CI).

Installs and tests pass. It includes some fixes that are not in 19.0; maybe worth a separate PR to 19.0 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.