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
Chaining named scope is no longer leaking to class level querying methods #32380
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…hods Active Record uses `scoping` to delegate to named scopes from relations for propagating the chaining source scope. It was needed to restore the source scope in named scopes, but it was caused undesired behavior that pollute all class level querying methods. Example: ```ruby class Topic < ActiveRecord::Base scope :toplevel, -> { where(parent_id: nil) } scope :children, -> { where.not(parent_id: nil) } scope :has_children, -> { where(id: Topic.children.select(:parent_id)) } end # Works as expected. Topic.toplevel.where(id: Topic.children.select(:parent_id)) # Doesn't work due to leaking `toplevel` to `Topic.children`. Topic.toplevel.has_children ``` Since rails#29301, the receiver in named scopes has changed from the model class to the chaining source scope, so the polluting class level querying methods is no longer required for that purpose. Fixes rails#14003.
kamipo
force-pushed
the
fix_leaking_scope
branch
from
February 5, 2019 15:40
ae582da
to
2935d07
Compare
kamipo
changed the title
Chaining named scope is no longer leaking to querying class methods
Chaining named scope is no longer leaking to class level querying methods
Feb 5, 2019
kamipo
added a commit
to kamipo/rails
that referenced
this pull request
Feb 13, 2019
…ying methods" This reverts rails#32380, since this may cause that silently leaking information when people upgrade the app. We need deprecation first before making this.
kamipo
added a commit
to kamipo/rails
that referenced
this pull request
Feb 15, 2019
…garded as leaked This deprecates using class level querying methods if the receiver scope regarded as leaked, since rails#32380 and rails#35186 may cause that silently leaking information when people upgrade the app. We need deprecation first before making those.
This was referenced Aug 19, 2019
consequently this |
8 tasks
alexdunae
added a commit
to rrn/acts_as_replaceable
that referenced
this pull request
Jun 6, 2021
This addresses a Rails 6.1 deprecation warning to address scope leakage: rails/rails#32380 `default_scoped` was introduced in Rails 4.1.8: https://apidock.com/rails/v6.1.3.1/ActiveRecord/Scoping/Named/ClassMethods/default_scoped
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Active Record uses
scoping
to delegate to named scopes from relationsfor propagating the chaining source scope. It was needed to restore the
source scope in named scopes, but it was caused undesired behavior that
pollute all class level querying methods.
Example:
Since #29301, the receiver in named scopes has changed from the model
class to the chaining source scope, so the polluting class level
querying methods is no longer required for that purpose.
Fixes #14003.