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
Fix unscoping bug in preload and includes #16367
Conversation
Tests are broken with this patch. |
Seems it broke cases designed to cover #5667. The way I understand that issue, though, is that it used |
Ignoring scoping closes a chance to unscope.
I see. I understand I'll find another way to fix circular preload without ignoring the scoping. |
I fixed broken tests. 93be88e In this line, the klass's preload/includes values are already preloaded/included. |
I'd combine both changelogs into one.
|
@@ -346,7 +346,7 @@ def reorder!(*args) # :nodoc: | |||
|
|||
VALID_UNSCOPING_VALUES = Set.new([:where, :select, :group, :order, :lock, | |||
:limit, :offset, :joins, :includes, :from, | |||
:readonly, :having]) | |||
:readonly, :having, :preload]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this change deserve an independent spec? It's behavior that could be reused for other purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preload changes preload_values.
:preload is in not SINGLE_VALUE_METHODS but MULTI_VALUE_METHODS.
Thus symbol_unscoping changes preload_values and it works well.
I think the feature of unscoping preload itself is reasonable because currently unscoping includes is supported.
I'll add some tests which assert it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the test ensuring that unscoping preload works. 6c19f24
Then I squashed all commits into 1145c48.
Thank you for a nice suggestion. |
Change preload not to ignore scoping. Preload and includes scope is still ignored for rails#5667. And preload is changed to be unscopable.
This PR fixes #11036.
Currently unscoped block does not work for
includes
andpreload
.I changed
ActiveRecord::Associations::Preloader
to use all instead of default_scoped.And ignore :preload and :includes scope to pass #5667.