未验证 提交 c7dfe33f 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #31751 from yoreek/clear_transaction_state_when_ar_object_is_duped

Clear the transaction state when AR object is duped
* Clear the transaction state when AR object is duped.
Fixes #31670.
*Yuriy Ustushenko*
* Support for PostgreSQL foreign tables.
*fatkodima*
......
......@@ -382,8 +382,10 @@ def initialize_dup(other) # :nodoc:
_run_initialize_callbacks
@new_record = true
@destroyed = false
@new_record = true
@destroyed = false
@_start_transaction_state = {}
@transaction_state = nil
super
end
......
......@@ -3,6 +3,7 @@
require "cases/helper"
require "models/reply"
require "models/topic"
require "models/movie"
module ActiveRecord
class DupTest < ActiveRecord::TestCase
......@@ -157,5 +158,20 @@ def test_dup_without_primary_key
record.dup
end
end
def test_dup_record_not_persisted_after_rollback_transaction
movie = Movie.new(name: "test")
assert_raises(ActiveRecord::RecordInvalid) do
Movie.transaction do
movie.save!
duped = movie.dup
duped.name = nil
duped.save!
end
end
assert !movie.persisted?
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册