activerecord: No warning for return out of transaction block without writes#39453
Merged
eileencodes merged 2 commits intorails:masterfrom May 28, 2020
Merged
Conversation
eileencodes
reviewed
May 27, 2020
Member
eileencodes
left a comment
There was a problem hiding this comment.
I left a comment for a minor change, otherwise this looks good. Thanks for the quick turn around.
0090de4 to
4332613
Compare
If the transaction block is exited due to a timeout, we don't want to change what exception is raised. Also, not raising will allow the transaction to be conveniently aborted by an `return` or `break` statement.
…writes It doesn't matter if the transaction is rolled back or committed if it wasn't written to, so we can avoid warning about a breaking change.
Member
|
Thanks Dylan! |
This was referenced May 4, 2022
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#29333 introduced a deprecation warning for transaction blocks that are exited with
break,returnorthrowwhich has a couple of problems which @eileencodes brought to my attention (#29333 (comment)).That deprecation warning was introduced for code like
because it wasn't expected that the timeout would commit the transaction. However, the warning says the next version of rails will raise an exception and it would also be unexpected for that code to not result in a Timeout::Error exception. So the first commit in this PR changes the deprecation warning message to remove the mention of raising.
The other problem is with deprecation warnings from returns out of a transaction block that hasn't made any writes to the transaction, where it doesn't matter if the transaction is rolled back or committed. E.g.
The second commit in this PR avoids that deprecation warning by marking open transactions as having written on the first write query, then making the warning conditional on the current transaction having written.
Other Information
Since the #29333 hasn't been released, I've just edited the existing CHANGELOG entry for it.