Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't clear transaction state after manual rollback #32862

Merged
merged 1 commit into from May 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 1 addition & 7 deletions activerecord/lib/active_record/transactions.rb
Expand Up @@ -382,13 +382,7 @@ def with_transaction_returning_status
status = nil
self.class.transaction do
add_to_transaction
begin
status = yield
rescue ActiveRecord::Rollback
clear_transaction_record_state
status = nil
end

status = yield
raise ActiveRecord::Rollback unless status
end
status
Expand Down
12 changes: 12 additions & 0 deletions activerecord/test/cases/transactions_test.rb
Expand Up @@ -292,6 +292,18 @@ def after_create_for_transaction
assert_nil new_topic.id, "The topic should not have an ID"
end

def test_callback_rollback_in_create_with_rollback_exception
topic = Class.new(Topic) {
def after_create_for_transaction
raise ActiveRecord::Rollback
end
}

new_topic = topic.create(title: "A new topic")
assert !new_topic.persisted?, "The topic should not be persisted"
assert_nil new_topic.id, "The topic should not have an ID"
end

def test_nested_explicit_transactions
Topic.transaction do
Topic.transaction do
Expand Down