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
Remove memoization for limited_count #43816
Conversation
since if a relation's records are not loaded and @limited_count gets set, when some of the records are subsequently deleted then the memoized value for @limited_count is inconsistent with the value returned by a call to size. In such a case calls to one? and many? can be incorrect.
Remove memoization for limited_count
The build failures here are related. I believe this effectively reverts #42143, so perhaps it should be entirely reverted? |
Good find. I think we can keep both if we invalidate the cache of |
I'm going to revert this PR in the mean time. |
…lation" This reverts commit 551f11d. CI is broken.
Sure. In the test: posts.where.not(id: Post.first).destroy_all the call to If there's no obvious way to do the cache invalidation, should we keep with the memoization removal, retain the |
Hmm, yeah, I think that test is unrepresentative of expected behaviour (even if it was the historical observable behaviour). Relations are expected to memoize information about what's in the database after they query it, and will not notice if the database is manipulated afterwards [except very directly through that relation itself]. If you |
I guess the strange behaviour here though is that the calls to |
Sorry, I made the same mistake I did in #42143 -- my brain remains entirely (and falsely) convinced that |
Summary
If a relation's records are not loaded and
@limited_count
gets set, when some of the records are subsequently deleted then the memoized value for@limited_count
is inconsistent with the value returned by a call to size. In such a case calls toone?
andmany?
can be incorrect. This is a fix for #43801.Other Information