1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Remove ActiveRecord::Transactions#rollback_active_record_state!

`rollback_active_record_state!` was removed from `save!` but not `save`
in da840d13da. I believe that leaving it
in `save` was a mistake, since that commit was intended to move the
rollback logic from the `save`/`save!` call to the transaction stack.

As of 67d8bb963d the record's original
state is lazily restored the first time it's accessed after the
transaction, instead of when a rollback occurs. This means that the call
to `restore_transaction_record_state` here has no effect: the record's
transaction level is incremented twice (in rollback_active_record_state!
and `with_transaction_returning_status`), isn't decremented again until
the the `ensure` block runs, and won't hit zero until the next time
`sync_with_transaction_state` is called.
This commit is contained in:
Eugene Kenny 2018-05-13 02:02:37 +01:00
parent 6fac9bd599
commit 48007d5390

View file

@ -306,9 +306,7 @@ module ActiveRecord
end
def save(*) #:nodoc:
rollback_active_record_state! do
with_transaction_returning_status { super }
end
with_transaction_returning_status { super }
end
def save!(*) #:nodoc:
@ -319,17 +317,6 @@ module ActiveRecord
with_transaction_returning_status { super }
end
# Reset id and @new_record if the transaction rolls back.
def rollback_active_record_state!
remember_transaction_record_state
yield
rescue Exception
restore_transaction_record_state
raise
ensure
clear_transaction_record_state
end
def before_committed! # :nodoc:
_run_before_commit_without_transaction_enrollment_callbacks
_run_before_commit_callbacks