From 248da11504894ddb7c345a0ab320f923bb6ab99b Mon Sep 17 00:00:00 2001 From: Guewen Baconnier Date: Wed, 14 Aug 2019 15:44:34 +0200 Subject: [PATCH] fixup! [10.0] Remove RowExclusiveLock on exception_rule --- base_exception/models/base_exception.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/base_exception/models/base_exception.py b/base_exception/models/base_exception.py index 36216c7234b..f57c38b914a 100644 --- a/base_exception/models/base_exception.py +++ b/base_exception/models/base_exception.py @@ -121,6 +121,18 @@ def detect_exceptions(self): ).update(to_add) if records_with_exception: all_exception_ids.append(rule.id) + # Cumulate all the records to attach to the rule + # before linking. We don't want to call "rule.write()" + # which would: + # * write on write_date so lock the expection.rule + # * trigger the recomputation of "main_exception_id" on + # all the sale orders related to the rule, locking them all + # and preventing concurrent writes + # Reversing the write by writing on SaleOrder instead of + # ExceptionRule fixes the 2 kinds of unexpected locks. + # It should not result in more queries than writing on ExceptionRule: + # the "to remove" part generates one DELETE per rule on the relation table + # and the "to add" part generates one INSERT (with unnest) per rule. for rule_id, records in rules_to_remove.iteritems(): records.write({'exception_ids': [(3, rule_id,)]}) for rule_id, records in rules_to_add.iteritems():