Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

New "scoped" implementation since v2.3.9 breaks chained scopes with custom methods

#5915

Using git-bisect, I tracked down an issued to commit bfbdeea, "Use bind instead of instance_exec cause it may be causing memory leaks. Also, provide a simpler and sane implementation for scoped.". This commit changes how scoped works such that it no longer propagates custom methods on scopes.

This is an example of the broken case:

  class MyModel < ActiveRecord::Base
    has_many :widgets do
      def limited_to(x)
        scoped(:conditions => ...)
      end

      def fnord
        "a fnord"
      end
    end
  end

  class Widget < ActiveRecord::Base
  end

  MyModel.find(:first).widgets.limited_to(true).fnord # <- EXPLODES undefined method 'fnord' for #<Class:...>

I'm not sure exactly how the scoping functionality changed with this commit, but it broke this case.

Reported by Logan Bowers · November 3rd, 2010 @ 11:34 PM

State: stale
Milestone: none
Assigned to: José Valim José Valim
Importance: Low

Activity

  1. Logan Bowers
    Logan Bowers
    • Assigned user set to José Valim

    November 3rd, 2010 @ 11:35 PM

  2. Logan Bowers
    Logan Bowers
    • Tag set to bug, regression

    November 3rd, 2010 @ 11:43 PM

  3. José Valim
    José Valim
    • State changed from resolved to open
    • Importance changed from to Low

    This is the commit hash: https://github.com/rails/rails/commit/bfbdeeae3080c89a0b27e42d684cb...

    I am a bit busy this week, but I will try to find sometime to take a look at it next one.

    November 4th, 2010 @ 12:17 AM

  4. James Le Cuirot
    James Le Cuirot

    Interesting. I tried this on an app of mine and it worked. But that app has a fair few modifications to Rails. I switched to vanilla and it failed as you've showed. I'll try to find out what I've done that fixes it. This probably goes without saying but I recommend you don't revert that old commit, even temporarily, the memory leak was massive.

    November 4th, 2010 @ 10:45 AM

  5. James Le Cuirot
    James Le Cuirot

    Never mind, ignore that. Long story. ;)

    November 4th, 2010 @ 10:52 AM

  6. Neeraj Singh
    Neeraj Singh

    Attached is patch with test for 2-3-stable. Needless to say all the tests are passing with the patch.

    November 4th, 2010 @ 07:28 PM

  7. Neeraj Singh
    Neeraj Singh

    For the last couple of days I am not able to upload any attachment. Not sure what happend. Is it LH issue or is it my browser. Next time I will try FF.

    In the meantime the attachment is on dropbox. Sorry about this. I will try FF and if that does not work I will report and issue to entp.

    http://dl.dropbox.com/u/7468116/patch-for-2-3-stable.diff

    November 4th, 2010 @ 07:32 PM

  8. Santiago Pastorino
    Santiago Pastorino

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 5th, 2011 @ 08:56 PM

  9. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 5th, 2011 @ 08:56 PM