Permalink
Browse files

Allow rollback if there is an exception in after_commit transaction

  • Loading branch information...
ivantsepp authored and pat committed Mar 14, 2016
1 parent 3f90c00 commit 364f159ac88f90f0574a8c5cd7ef38facf3fc00d
Showing with 7 additions and 1 deletion.
  1. +7 −1 lib/after_commit/connection_adapters.rb
@@ -50,7 +50,13 @@ def commit_db_transaction_with_callback
# should recieve the after_commit callback, but do fire the after_rollback
# callback for each record that failed to be committed.
def rollback_db_transaction_with_callback
- return if @disable_rollback
+ if @disable_rollback
+ # if rollback is called and @disable_rollback is true, then ActiveRecord is trying to
+ # rollback from an exception in an `after_commit` block. Only rollback once by checking
+ # to see if we are back at the top level `after_commit` transaction
+ rollback_db_transaction_without_callback if transaction_pointer == 0
+ return
+ end
increment_transaction_pointer
begin
result = nil

0 comments on commit 364f159

Please sign in to comment.