Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fix #6635. We should call Scoping methods, before calling Array methods.

  • Loading branch information...
commit cd1be1acc68221fbdfab0d13211d40bdeae630dc 1 parent 42259f6
@kennyj kennyj authored
10 activerecord/lib/active_record/relation/delegation.rb
@@ -32,12 +32,12 @@ def respond_to?(method, include_private = false)
def method_missing(method, *args, &block)
- if Array.method_defined?(method)
- ::ActiveRecord::Delegation.delegate method, :to => :to_a
- to_a.send(method, *args, &block)
- elsif @klass.respond_to?(method)
+ if @klass.respond_to?(method)
scoping { @klass.send(method, *args, &block) }
+ elsif Array.method_defined?(method)
+ ::ActiveRecord::Delegation.delegate method, :to => :to_a
+ to_a.send(method, *args, &block)
elsif arel.respond_to?(method)
::ActiveRecord::Delegation.delegate method, :to => :arel
arel.send(method, *args, &block)
@@ -46,4 +46,4 @@ def method_missing(method, *args, &block)
9 activerecord/test/cases/named_scope_test.rb
@@ -45,6 +45,15 @@ def test_delegates_finds_and_calculations_to_the_base_class
assert_equal Topic.average(:replies_count), Topic.base.average(:replies_count)
+ def test_method_missing_priority_when_delegating
+ klazz = do
+ self.table_name = "topics"
+ scope :since, { where('written_on >= ?', - }
+ scope :to, { where('written_on <= ?', }
+ end
+ assert_equal,
+ end
def test_scope_should_respond_to_own_methods_and_methods_of_the_proxy
assert Topic.approved.respond_to?(:limit)
assert Topic.approved.respond_to?(:count)

13 comments on commit cd1be1a


ActiveModel::Serializer is effected by this change.


As a random note, you can link to issues in other repos with user/project#number

Like josevalim/active_model_serializers#81


I'm :disappointed: that this shipped along with a critical security fix. I can't apply the patch until this issue is resolved.


@sferik pull requests are always welcome.


@kennyj could you check this please?

I don't have time now. But this is in my todo list. A is_a? check should solve.


@rafaelfranca Would you accept a pull request to revert this commit?


@sferik I would try to fix it since this commit is a bug fix, but we can revert it and try to fix the bug in another way. What do you thing?


@sferik @rafaelfranca Please tell me more details. I don't realize a problem.


@kennyj I don't know the real reason but seems like josevalim/active_model_serializers is expecting that Array methods have precedence over AR::Relation. josevalim/active_model_serializers#81 shows the error but we need to research.


I believe that ActiveModel Serializers can be updated. The question is was this commit a needed and expected change for 3.2.6.

Thank god for tests! Its stop me from upgrading to 3.2.6 so far.


Yes, this is an expected change to a stable release since it is a bug fix.


I see... I realized that since 3.2.6 has ActiveModel Serializers problem, @sferik can't update his application from 3.2.5 (has security problem) to 3.2.6.
Yes, I'll check it :-)


Hi Everyone. I couldn't reproduce AM Serializers's problem ;-)
Please serve sample app or tell us the way to reproduce.

Please sign in to comment.
Something went wrong with that request. Please try again.