Permalink
Browse files

Cleaning up after_commit commit state at end of transaction to preven…

…t previous successful transactions from screwing up unsuccessful transactions
  • Loading branch information...
1 parent 622707f commit 76ff89cb49299c20596d8d73fb1e13bfc8d22925 Keith Simmons committed Apr 27, 2011
Showing with 9 additions and 6 deletions.
  1. +9 −6 lib/after_commit/after_savepoint.rb
@@ -43,6 +43,10 @@ def after_callback_transaction_committed?
def after_callback_mark_committed committed
(Thread.current[:after_callback_committed] ||= {})[unique_transaction_key] = committed
end
+
+ def after_callback_cleanup_committed
+ (Thread.current[:after_callback_committed] ||= {})[unique_transaction_key] = nil
+ end
def release_savepoint_with_callback
increment_transaction_pointer
@@ -56,16 +60,14 @@ def release_savepoint_with_callback
release_savepoint_without_callback
after_callback_mark_committed true
-
trigger_after_commit_callbacks
trigger_after_commit_on_create_callbacks
trigger_after_commit_on_save_callbacks
trigger_after_commit_on_update_callbacks
trigger_after_commit_on_destroy_callbacks
+ AfterCommit.cleanup(self)
+ after_callback_cleanup_committed
ensure
- if after_callback_transaction_committed?
- AfterCommit.cleanup(self)
- end
decrement_transaction_pointer
end
end
@@ -85,8 +87,9 @@ def rollback_to_savepoint_with_callback
end
ensure
AfterCommit.cleanup(self)
- end
- decrement_transaction_pointer
+ after_callback_cleanup_committed
+ decrement_transaction_pointer
+ end
end
alias_method_chain :rollback_to_savepoint, :callback
end

0 comments on commit 76ff89c

Please sign in to comment.