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

Clear the transaction state when AR object is duped #31751

Merged

Conversation

yoreek
Copy link
Contributor

@yoreek yoreek commented Jan 20, 2018

Fixes #31670

@rails-bot
Copy link

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.

@kamipo
Copy link
Member

kamipo commented Jan 23, 2018

Original issue is "ActiveRecord persisted? returns true after rollback when using duped record".

Can you test that issue is fixed?

@yoreek
Copy link
Contributor Author

yoreek commented Jan 23, 2018

@kamipo, here is the test before and after the fix:

$ git co master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
$ bundle exec ../persisted_after_rollback.rb
Active Record 5.2.0.beta2
-- create_table(:users, {:force=>true})
-> 0.0050s
Create a clone using dup
persisted? = true
Create a clone using new
persisted? = false

$ git co clear_transaction_state_when_ar_object_is_duped
Switched to branch 'clear_transaction_state_when_ar_object_is_duped'
$ bundle exec ../persisted_after_rollback.rb
Active Record 5.2.0.beta2
-- create_table(:users, {:force=>true})
-> 0.0050s
Create a clone using dup
persisted? = false
Create a clone using new
persisted? = false

@kamipo
Copy link
Member

kamipo commented Jan 23, 2018

Yeah, can you add the test in the commit to catch a future regression?

@yoreek yoreek force-pushed the clear_transaction_state_when_ar_object_is_duped branch 2 times, most recently from a71af43 to aa8de3b Compare January 24, 2018 07:49
@yoreek
Copy link
Contributor Author

yoreek commented Jan 24, 2018

@kamipo done

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)
Copy link
Member

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.

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 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 ?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@kamipo kamipo left a 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?

@yoreek yoreek force-pushed the clear_transaction_state_when_ar_object_is_duped branch from aa8de3b to 226116a Compare January 25, 2018 03:10
@kamipo kamipo merged commit c7dfe33 into rails:master Jan 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants