From 846e802f6fb0e9ff9ae1b25577521f1fa1e6fed7 Mon Sep 17 00:00:00 2001 From: "Paul A. Jungwirth" Date: Mon, 3 Oct 2016 12:18:36 -0700 Subject: [PATCH] Lock to parent object to prevent deadlocks updating most_recent --- 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 c0932cbe..81b18d61 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!