From 787dc6bc7ce75ccb10b1d80b00ab3e01d86ac6d1 Mon Sep 17 00:00:00 2001 From: Harry Maclean Date: Tue, 16 May 2017 09:43:30 +0100 Subject: [PATCH] Lock the parent row when transitioning This prevents deadlocks in some cases. See https://github.com/gocardless/statesman/pull/228 for more info. This branch is only here to test the change. --- lib/statesman/adapters/active_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/statesman/adapters/active_record.rb b/lib/statesman/adapters/active_record.rb index 4ce535a1..ab912cf1 100644 --- a/lib/statesman/adapters/active_record.rb +++ b/lib/statesman/adapters/active_record.rb @@ -70,7 +70,7 @@ def create_transition(from, to, metadata) transition = transitions_for_parent.build(transition_attributes) - ::ActiveRecord::Base.transaction do + @parent_model.with_lock do @observer.execute(:before, from, to, transition) unset_old_most_recent transition.save!