提交 198d9e3d 编写于 作者: A Arthur Neves

Reverts "Fix bugs with changed attributes tracking when transaction gets rollback"

We are reverting these commits, because there are other caveats related
to dirty attributes not being restored when a transaction is rollback.
For instance, nested transactions cannot proper restore the dirty
attributes state after a rollback.

At the moment, the dirty attributes are scoped by the transaction.
When we call `.save` on a record, the dirty attributes will be reset even
if the transaction gets rollback.

[related #13166]
[related #15018]
[related #15016]
[closes #15019]

This reverts commits
* bab48f0a
  * b0fa7cf3.
* 73fb39b6
  * 37c23892.
  * 8d8d4f15

Revert "Merge pull request #13166 from bogdan/transaction-magic"
上级 0a7beb1b
......@@ -12,12 +12,6 @@
*Paul B.*
* Keep track of dirty attributes after transaction is rollback.
Related #13166.
*Bogdan Gusiev* *arthurnn*
* Add support for module-level `table_name_suffix` in models.
This makes `table_name_suffix` work the same way as `table_name_prefix` when
......
......@@ -350,7 +350,6 @@ def remember_transaction_record_state #:nodoc:
end
@_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) + 1
@_start_transaction_state[:frozen?] = @attributes.frozen?
@_start_transaction_state[:changed_attributes] ||= changed_attributes.dup
end
# Clear the new record state and id of a record.
......@@ -369,9 +368,6 @@ def restore_transaction_record_state(force = false) #:nodoc:
@attributes = @attributes.dup if @attributes.frozen?
@new_record = restore_state[:new_record]
@destroyed = restore_state[:destroyed]
changed_attributes.replace(restore_state[:changed_attributes]).delete_if do |attribute, old_value|
old_value == @attributes[attribute]
end
if restore_state.has_key?(:id)
write_attribute(self.class.primary_key, restore_state[:id])
else
......
......@@ -274,48 +274,6 @@ def test_invalid_keys_for_transaction
end
end
def test_rollback_when_changing_inside_transaction
assert !@first.approved?
Topic.transaction do
@first.approved = true
@first.save!
raise ActiveRecord::Rollback
end
assert @first.approved
assert @first.changes["approved"]
@first.save!
assert @first.reload.approved
end
def test_rollback_when_changing_outside_transaction
assert !@first.approved?
@first.approved = true
Topic.transaction do
@first.save!
raise ActiveRecord::Rollback
end
assert @first.changes["approved"]
assert @first.approved
@first.save!
assert @first.reload.approved
end
def test_rollback_when_changing_back_to_prev_stage
assert !@first.approved?
Topic.transaction do
@first.approved = true
@first.save!
@first.approved = false
@first.save!
raise ActiveRecord::Rollback
end
assert !@first.approved
assert !@first.changes["approved"]
@first.save!
assert !@first.reload.approved
end
def test_force_savepoint_in_nested_transaction
Topic.transaction do
@first.approved = true
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册