Skip to content

Commit

Permalink
fixup! [10.0] Remove RowExclusiveLock on exception_rule
Browse files Browse the repository at this point in the history
  • Loading branch information
guewen committed Aug 14, 2019
1 parent cf3234d commit 248da11
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions base_exception/models/base_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 248da11

Please sign in to comment.