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 ActiveRecord object memoized by take #36985

Merged
merged 1 commit into from Aug 20, 2019

Conversation

anmolarora
Copy link
Contributor

Summary

ActiveRecord object is memoized when take is called on a relation which is returned when where/find_by is called on the same relation.
This memoized state of the object needs to be cleared.

Fixes #36977

Post.create!(title: idx.to_s, body: idx.to_s)
end

posts = Post.all
Copy link
Member

Choose a reason for hiding this comment

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

Let's put an order(:title) on here, otherwise the test will fail sporadically when the database happens to return "3" in the first take

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is only one Post in the DB with title '3'.
Will this still be a problem?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, sorry, I was concerned that "3" might get [legitimately] chosen as first_post, and then the assert_not_equal would fail -- but it's comparing object_id, so it will actually be fine even if they both contain the same row. 👍

@matthewd matthewd merged commit ebd7f2a into rails:master Aug 20, 2019
rafaelfranca pushed a commit that referenced this pull request Aug 20, 2019
Clear ActiveRecord object memoized by take
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants