Repository navigation
Conversation
_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.
|
Hi @hparfr, @sebastienbeau, |
ae2242b to
eb3a5d3
Compare
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.
eb3a5d3 to
fcd7b89
Compare
|
Hi @grindtildeath @simahawk @rousseldenis @hparfr, as you reviewed #3590 / #3741: this is a follow-up for the cases where the second cursor of |
|
#3739 and #3866 both fix the hang when the second cursor of 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) |
|
I agree... Thanks. |
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 patchEnvironmentso the second cursor is the test one. On a real database we got it in two places:_check_exception()runs from a constraint, so the order is always written (and locked) before the detection. The request hangs.ignore_exceptionand then callsaction_confirm(). We gotcould not serialize accessthere.Changes
_check_exception()detects the exceptions withbase_exception_no_rollbackfor its main records. TheValidationErrorraised next already rolls back the transaction, so there is nothing to keep with a second cursor._new_cursor_can_lock(): before writing with the second cursor, flush the pending writes on the rows and try to lock them withFOR NO KEY UPDATE NOWAIT(aswebsite_saledoes 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. theignore_exceptionset by the wizard) does not lock the row yet: the second cursor commits first and the ongoing transaction then fails withcould not serialize access due to concurrent delete.ignore_exceptionto 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 theValidationErrorwith the rule names again instead ofBaseExceptionError. [18.0][FIX] base_exception: Rollback transaction if we detect exceptions #3590 targetedaction_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.NOWAITasERROR: could not obtain lock on row in relation ...(55P03). It is expected; Odoo does not log it.OCA/sale-workflow needs the same check in the
sale.order.lineoverride: OCA/sale-workflow#4798.