Skip to content

[18.0][FIX] base_exception: do not wait on rows locked by the ongoing transaction - #3866

Open
gal-adhoc wants to merge 3 commits into
OCA:18.0from
adhoc-dev:18.0-h-132959-gal
Open

gal-adhoc wants to merge 3 commits into
OCA:18.0from
adhoc-dev:18.0-h-132959-gal

Conversation

@gal-adhoc

@gal-adhoc gal-adhoc commented Nov 17, 2026 •

Copy link
Copy Markdown

Follow-up of #3741 and OCA/sale-workflow#4600.

The second cursor of detect_exceptions() waits forever when the ongoing transaction already wrote on the records it has to update: the row lock is held by the transaction the worker is running. OCA tests do not see it because they patch Environment so the second cursor is the test one. On a real database we got it in two places:

  1. Saving a change on a confirmed sale order. _check_exception() runs from a constraint, so the order is always written (and locked) before the detection. The request hangs.
  2. Any caller that writes on the record and then confirms it, e.g. the exception wizard: "Ignore" writes ignore_exception and then calls action_confirm(). We got could not serialize access there.

Changes

  • _check_exception() detects the exceptions with base_exception_no_rollback for its main records. The ValidationError raised next already rolls back the transaction, so there is nothing to keep with a second cursor.
  • New _new_cursor_can_lock(): before writing with the second cursor, flush the pending writes on the rows and try to lock them with FOR NO KEY UPDATE NOWAIT (as website_sale does in 18.0). If they are already locked, write the exceptions in the ongoing transaction. Without the flush, a write still in the ORM cache (e.g. the ignore_exception set by the wizard) does not lock the row yet: the second cursor commits first and the ongoing transaction then fails with could not serialize access due to concurrent delete.
  • The decision to raise is taken on the main records read through the second cursor, which does not see what the ongoing transaction wrote. Copy its ignore_exception to them first. This is not a regression of this PR: without it, "Ignore" in the wizard raises again when nothing has to be written on the main records, e.g. a sale order with exceptions only on its lines.

Behaviour changes

  • _check_exception() raises the ValidationError with the rule names again instead of BaseExceptionError. [18.0][FIX] base_exception: Rollback transaction if we detect exceptions #3590 targeted action_confirm() (overrides that wrote before the detection and got committed); on the constraint path the second cursor can never write, because the row is always locked at that point, so the popup could not show stored exceptions there anyway.
  • When the rows are locked, PostgreSQL logs the failed NOWAIT as ERROR: could not obtain lock on row in relation ... (55P03). It is expected; Odoo does not log it.
  • When the rows are locked and the records must be rolled back, the exceptions are written in the ongoing transaction and lost with the rollback. The worker no longer hangs. With "Ignore" and confirm nothing is raised and the record is confirmed.

OCA/sale-workflow needs the same check in the sale.order.line override: OCA/sale-workflow#4798.

_check_exception() runs from a constraint, after the records were
written in the ongoing transaction. The second cursor of
detect_exceptions() then waits forever on the row lock held by that
transaction, e.g. when saving a change on a confirmed sale order.

Detect the exceptions with base_exception_no_rollback for the main
records: they are stored in the ongoing transaction, and the
ValidationError raised next already rolls it back.
@OCA-git-bot

Copy link
Copy Markdown
Contributor

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

When the ongoing transaction already wrote on the records, the second
cursor of detect_exceptions() waits forever on their row lock. This
happens with any caller that writes on a record and then confirms it,
e.g. the exception wizard that sets ignore_exception before confirming.

Flush the pending writes on the rows and try to lock them with NOWAIT
first, and write the exceptions in the ongoing transaction when they are
already locked. In that case they are not kept after the rollback, but
the worker no longer hangs or fails to serialize.
…tion

detect_exceptions() decides whether to raise by reading the main records
through the second cursor, which does not see what the ongoing
transaction wrote. When the exception wizard sets ignore_exception and
confirms, the second cursor still reads it as False and the confirmation
raises again. This happens whenever nothing has to be written on the
main records, e.g. a sale order with exceptions only on its lines.

Copy the ignore_exception of the ongoing transaction to the records read
through the second cursor before deciding.
@gal-adhoc
gal-adhoc marked this pull request as ready for review November 17, 2026 19:52
@gal-adhoc

Copy link
Copy Markdown
Author

Hi @grindtildeath @simahawk @rousseldenis @hparfr, as you reviewed #3590 / #3741: this is a follow-up for the cases where the second cursor of detect_exceptions() hangs or fails to serialize because the ongoing transaction already wrote on the records (saving a confirmed order, the "Ignore" wizard). Details and the behaviour changes are in the description. Tested on a copy of a production database without the compatibility modules we use on top of base_exception. Could you have a look when you have time? Thanks!

@bosd

bosd commented Nov 24, 2026

Copy link
Copy Markdown

#3739 and #3866 both fix the hang when the second cursor of detect_exceptions() waits on rows locked by the ongoing transaction. Only one of them should land.

Combining the two would work best, I think:

@sergio-teruel @gal-adhoc could you agree on one PR and close the other?

cc @hparfr @sebastienbeau (maintainers)

@sergio-teruel

Copy link
Copy Markdown
Contributor

I agree... Thanks.

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.

4 participants