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

Deprecate delegating to arel in Relation #29619

Merged

Conversation

kamipo
Copy link
Member

@kamipo kamipo commented Jun 28, 2017

Active Record doesn't rely delegating to arel in the internal since
425f2ca. The delegation is a lower priority than delegating to klass,
so it is pretty unclear which method is delegated to arel.

For example, bind_values method was removed at b06f64c (a series of
changes 79f71d3...b06f64c). But a
relation still could respond to the method because arel also have the
same named method (#28976).

Removing the delegation will achieve predictable behavior.

@@ -89,6 +89,9 @@ def method_missing(method, *args, &block)
self.class.delegate_to_scoped_klass(method)
scoping { @klass.public_send(method, *args, &block) }
elsif arel.respond_to?(method)
ActiveSupport::Deprecation.warn \
"Delegating #{method} to arel is deprecated and will be removed in Rails 5.3. " \
"Use relation.arel.#{method} instead."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't arel still private API? So the delegation makes sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Better to say that is going to be removed with no replacement. Also the next version of Rails after 5.2 is 6.0

Active Record doesn't rely delegating to `arel` in the internal since
425f2ca. The delegation is a lower priority than delegating to `klass`,
so it is pretty unclear which method is delegated to `arel`.

For example, `bind_values` method was removed at b06f64c (a series of
changes rails/rails@79f71d3...b06f64c). But a
relation still could respond to the method because `arel` also have the
same named method (rails#28976).

Removing the delegation will achieve predictable behavior.
@kamipo kamipo force-pushed the deprecate_delegating_to_arel_in_relation branch from 848419d to d9fca84 Compare June 29, 2017 14:09
@kaspth kaspth merged commit a317af9 into rails:master Jun 29, 2017
@kaspth
Copy link
Contributor

kaspth commented Jun 29, 2017

Great!

@kamipo
Copy link
Member Author

kamipo commented Jun 29, 2017

Thanks!

@samstickland
Copy link

Not sure if this is the right place for this question, but I'm unsure how to move this to non-deprecated calls (short of manually generating SQL):

class TimesheetBlock
  scope :with_entries, -> {
    where(TimesheetEntry.where('timesheet_block_id = timesheet_blocks.id').exists)
  }
end

This generates SQL like this:

SELECT "timesheet_blocks".* FROM "timesheet_blocks" WHERE EXISTS (SELECT "timesheet_entries".* FROM "timesheet_entries" WHERE (timesheet_block_id = timesheet_blocks.id))

But gives this deprecation warning:

Delegating exists to arel is deprecated and will be removed in Rails 6.0

@kamipo
Copy link
Member Author

kamipo commented May 28, 2018

Please use .arel.exists instead.

@samstickland
Copy link

@kamipo Thanks!

koic added a commit to koic/24pullrequests that referenced this pull request Sep 5, 2018
This commit suppresses the following Active Record warnings.

```console
DEPRECATION WARNING: Delegating exists to arel is deprecated and will be
removed in Rails 6.0. (called from pull_request_filter at
/Users/koic/src/github.com/24pullrequests/24pullrequests/app/models/aggregation_filter.rb:7)

DEPRECATION WARNING: Delegating with to arel is deprecated and will be
removed in Rails 6.0. (called from block (4 levels) in <top (required)>
at /Users/koic/src/github.com/24pullrequests/24pullrequests/spec/controllers/users_controller_spec.rb:16)
```

This patch is based on the following comment.
rails/rails#29619 (comment)
andrew pushed a commit to 24pullrequests/24pullrequests that referenced this pull request Sep 5, 2018
This commit suppresses the following Active Record warnings.

```console
DEPRECATION WARNING: Delegating exists to arel is deprecated and will be
removed in Rails 6.0. (called from pull_request_filter at
/Users/koic/src/github.com/24pullrequests/24pullrequests/app/models/aggregation_filter.rb:7)

DEPRECATION WARNING: Delegating with to arel is deprecated and will be
removed in Rails 6.0. (called from block (4 levels) in <top (required)>
at /Users/koic/src/github.com/24pullrequests/24pullrequests/spec/controllers/users_controller_spec.rb:16)
```

This patch is based on the following comment.
rails/rails#29619 (comment)
tigefa4u pushed a commit to tigefa4u/gitlabhq that referenced this pull request Aug 16, 2019
As mentioned in rails/rails#29619, this removes
this warning message:

```
Delegating join_sources to arel is deprecated and will be removed in
Rails 6.0. (called from project_clusters_base_query at
app/models/clusters/clusters_hierarchy.rb:62)
```

Part of https://gitlab.com/gitlab-org/gitlab-ce/issues/61451
tigefa4u pushed a commit to tigefa4u/gitlabhq that referenced this pull request Aug 21, 2019
As mentioned in rails/rails#29619, this removes
this warning message:

```
Delegating join_sources to arel is deprecated and will be removed in
Rails 6.0. (called from project_clusters_base_query at
app/models/clusters/clusters_hierarchy.rb:62)
```

Part of https://gitlab.com/gitlab-org/gitlab-ce/issues/61451
tigefa4u pushed a commit to tigefa4u/gitlabhq that referenced this pull request Aug 26, 2019
As mentioned in rails/rails#29619, this removes
this warning message:

```
Delegating join_sources to arel is deprecated and will be removed in
Rails 6.0. (called from project_clusters_base_query at
app/models/clusters/clusters_hierarchy.rb:62)
```

Part of https://gitlab.com/gitlab-org/gitlab-ce/issues/61451
jmartin-tech added a commit to jmartin-tech/metasploit-credential that referenced this pull request Apr 24, 2020
Delegate directly to Arel to remove Rails 5 deprecation.
See: rails/rails#29619
jmartin-tech added a commit to jmartin-tech/metasploit-credential that referenced this pull request Apr 24, 2020
Delegate directly to Arel to remove Rails 5 deprecation.
See: rails/rails#29619
arvados-bot pushed a commit to arvados/arvados that referenced this pull request Aug 17, 2020
Explained at: rails/rails#29619 (comment)

Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants