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
Clear the transaction state when AR object is duped #31751
Clear the transaction state when AR object is duped #31751
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @sgrif (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
Original issue is "ActiveRecord persisted? returns true after rollback when using duped record". Can you test that issue is fixed? |
@kamipo, here is the test before and after the fix: $ git co master $ git co clear_transaction_state_when_ar_object_is_duped |
Yeah, can you add the test in the commit to catch a future regression? |
a71af43
to
aa8de3b
Compare
@kamipo done |
activerecord/test/cases/dup_test.rb
Outdated
def test_dup_transaction_state_and_transaction_record_state_are_cleared | ||
topic = Topic.first | ||
topic.send(:set_transaction_state, ActiveRecord::ConnectionAdapters::TransactionState.new(:rollback)) | ||
topic.send(:remember_transaction_record_state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to test internal states with private methods as long as it can be tested from public API.
And also, this test case does not show that the state of the record when the transaction was rolled back has been fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for review.
This test only checks that the transaction state is cleared in the duped record. I think that we must clear this state as well as other statuses. Do you think it is necessary to test the complete scheme with the rollback of the transaction?
And, unfortunately I did not find a public methods to access to @transaction_state
and @_start_transaction_state
, could you help me ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these are internal states we don't have any way to access to the states.
So it is enough to test the transaction behavior which tested in the following test rather than testing the states.
The test_dup_record_not_persisted_after_rollback_transaction
sufficiently shows which behavior is fixed.
So we simply remove the test_dup_transaction_state_and_transaction_record_state_are_cleared
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I removed the test and added the entry to CHANGELOG.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add CHANGELOG entry what issue is fixed?
aa8de3b
to
226116a
Compare
Fixes #31670