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

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

@anmolarora anmolarora force-pushed the 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
Copy link
Member

@matthewd matthewd Aug 20, 2019

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

Loading

Copy link
Contributor Author

@anmolarora anmolarora Aug 20, 2019

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?

Loading

Copy link
Member

@matthewd matthewd Aug 20, 2019

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. 👍

Loading

@matthewd matthewd merged commit ebd7f2a into rails:master Aug 20, 2019
2 checks passed
Loading
rafaelfranca added a commit that referenced this issue 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