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
merged 1 commit into from Jan 25, 2018

Conversation

Projects
None yet
4 participants
@yoreek
Contributor

yoreek commented Jan 20, 2018

Fixes #31670

@rails-bot

This comment has been minimized.

rails-bot commented Jan 20, 2018

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

This comment has been minimized.

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

This comment has been minimized.

Contributor

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

This comment has been minimized.

Member

kamipo commented Jan 23, 2018

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

@yoreek

This comment has been minimized.

Contributor

yoreek commented Jan 24, 2018

@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)

This comment has been minimized.

@kamipo

kamipo Jan 24, 2018

Member

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.

This comment has been minimized.

@yoreek

yoreek Jan 24, 2018

Contributor

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 ?

This comment has been minimized.

@kamipo

kamipo Jan 25, 2018

Member

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.

This comment has been minimized.

@yoreek

yoreek Jan 25, 2018

Contributor

ok, I removed the test and added the entry to CHANGELOG.

@kamipo

Can you add CHANGELOG entry what issue is fixed?

@kamipo kamipo added the activerecord label Jan 24, 2018

@kamipo kamipo merged commit c7dfe33 into rails:master Jan 25, 2018

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
codeclimate All good!
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment