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

commented Aug 19, 2019

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

@rails-bot rails-bot bot added the activerecord label Aug 19, 2019

@anmolarora anmolarora force-pushed the anmolarora:fix-take-memoization branch from c5322ec to 2a65310 Aug 19, 2019

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

posts = Post.all

This comment has been minimized.

Copy link
@matthewd

matthewd Aug 20, 2019

Member

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

This comment has been minimized.

Copy link
@anmolarora

anmolarora Aug 20, 2019

Author Contributor

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

This comment has been minimized.

Copy link
@matthewd

matthewd Aug 20, 2019

Member

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

2 checks passed

buildkite/rails Build #63170 passed (14 minutes, 39 seconds)
Details
codeclimate All good!
Details
rafaelfranca added a commit that referenced this pull request Aug 20, 2019
Merge pull request #36985 from anmolarora/fix-take-memoization
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
You can’t perform that action at this time.