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

Remove extra decrement of transaction level #11434

Merged
merged 1 commit into from Jul 15, 2013

Conversation

pftg
Copy link
Contributor

@pftg pftg commented Jul 14, 2013

rollback_active_record_state! tries to restore model state on Exception
by invoking restore_transaction_record_state it decrement deep level by 1.

After restoring state, rollback_active_record_state! ensure that states should be cleared
and level decremented by invoking clear_transaction_record_state,
which cause the bug: because state already reduced in restore_transaction_record_state.

Removed double derement of transaction level
and removed duplicated code which clear transaction state for top level.

Closes: #4566

@pftg
Copy link
Contributor Author

pftg commented Jul 14, 2013

/cc @neerajdotname, @rafaelfranca, @jonleighton

@pftg
Copy link
Contributor Author

pftg commented Jul 14, 2013

I used tests from #9828 but they need some cleanup to use old test models, instead of adding new one.

@@ -355,13 +356,14 @@ def remember_transaction_record_state #:nodoc:
def clear_transaction_record_state #:nodoc:
@_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) - 1
@_start_transaction_state.clear if @_start_transaction_state[:level] < 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this added? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

`rollback_active_record_state!` tries to restore model state on `Exception`
by invoking `restore_transaction_record_state` it decrement deep level by `1`.

After restoring it ensure that states to be cleared
and level decremented by invoking `clear_transaction_record_state`,
which cause the bug: because state already reduced in `restore_transaction_record_state`.

Removed double derement of transaction level
and removed duplicated code which clear transaction state for top level.
@pftg
Copy link
Contributor Author

pftg commented Jul 14, 2013

Updated PR with clean tests and fixes based on feedback.

spastorino added a commit that referenced this pull request Jul 15, 2013
Remove extra decrement of transaction level
@spastorino spastorino merged commit 8833b82 into rails:master Jul 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Transaction not rolling back object state when using .save instead of .save!
2 participants