diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-05-19 10:40:27 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-05-19 10:40:27 +0900 |
commit | 5f8115a1859ee883b3289c1e5ed8e5924e4a61b4 (patch) | |
tree | 8677ff87666d7e58d2c0f909eba4c0ef4bdc7ca1 | |
parent | 870766017ab20541a1e3b10bf026d82522028028 (diff) | |
download | rails-5f8115a1859ee883b3289c1e5ed8e5924e4a61b4.tar.gz rails-5f8115a1859ee883b3289c1e5ed8e5924e4a61b4.tar.bz2 rails-5f8115a1859ee883b3289c1e5ed8e5924e4a61b4.zip |
Rollback correctly restore initial record id after double save
-rw-r--r-- | activerecord/lib/active_record/transactions.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/transactions_test.rb | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/transactions.rb b/activerecord/lib/active_record/transactions.rb index ccb2d57b03..82adb19f5b 100644 --- a/activerecord/lib/active_record/transactions.rb +++ b/activerecord/lib/active_record/transactions.rb @@ -383,8 +383,8 @@ module ActiveRecord # Save the new record state and id of a record so it can be restored later if a transaction fails. def remember_transaction_record_state - @_start_transaction_state[:id] = id @_start_transaction_state.reverse_merge!( + id: id, new_record: @new_record, destroyed: @destroyed, frozen?: frozen?, diff --git a/activerecord/test/cases/transactions_test.rb b/activerecord/test/cases/transactions_test.rb index 0d7857c0cf..5b685ca564 100644 --- a/activerecord/test/cases/transactions_test.rb +++ b/activerecord/test/cases/transactions_test.rb @@ -688,6 +688,7 @@ class TransactionTest < ActiveRecord::TestCase raise ActiveRecord::Rollback end + assert_nil topic.id assert_predicate topic, :new_record? end |