From 335b1fad507d71d75cece4f7a0e304ee0146d27d Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Fri, 11 Aug 2017 11:10:31 +0200 Subject: [PATCH] Prevent ActiveRecord::StatementInvalid: PG::InFailedSqlTransaction: ERROR: current transaction is aborted , commands ignored until end of transaction block issues. --- app/models/transaction.rb | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/models/transaction.rb b/app/models/transaction.rb index 25b94fa55..7d121c3bf 100644 --- a/app/models/transaction.rb +++ b/app/models/transaction.rb @@ -8,16 +8,22 @@ class Transaction ApplicationHandleInfo.current = options[:interface_handle] end ActiveRecord::Base.transaction do - PushMessages.init - yield - if options[:interface_handle] - ApplicationHandleInfo.current = original_interface_handle + begin + PushMessages.init + yield + if options[:interface_handle] + ApplicationHandleInfo.current = original_interface_handle + end + Observer::Transaction.commit( + disable_notification: options[:disable_notification], + disable: options[:disable], + ) + PushMessages.finish + rescue ActiveRecord::StatementInvalid => e + Rails.logger.error e.inspect + Rails.logger.error e.backtrace + raise ActiveRecord::Rollback end - Observer::Transaction.commit( - disable_notification: options[:disable_notification], - disable: options[:disable], - ) - PushMessages.finish end end end