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.

ActiveRecord::Associations::AssociationCollection#any? broken since rails-rev9199

#204

Hi!

I already posted this as a blog comment, mainly because I didn't think of Lighthouse at that moment :) Anyways, once again for the records ...

I just noticed that has_many :through is somehow broken when will_paginate is installed and enabled in rails rev9125. To be more precise, the AssociationCollection#any? method falls into infinite recursion yielding a StackLevelTooDeepError.

I’m currently using rails rev9215 and it seems to me that maybe rev9199 introduced this behavior. I’m not entirely sure wether it was exactly rev9199, although it seems to be the only changeset related to associations in the near past, my app was definitely working yesterday :) Also, my app is working fine with will_paginate on rev9199!

I love edgerails! I don’t want to freeze because of this issue, however fixing it myself is beyond my method_missing fu and general rails code knowledge and would take me time I currently simply can’t spend :(

Any help very much appreciated!

cheers Martin Gamsjaeger

Reported by Martin Gamsjaeger (snusnu) · April 2nd, 2008 @ 10:08 PM

State: resolved
Milestone: none
Assigned to: Mislav Mislav

Activity

  1. Aaron H.
    Aaron H.

    I believe I have a fix for this.

    Investigating has found that the issue lies in how will_paginate mixes in the paginate method_missing magic.

    In line 44 of finder.rb, will_paginate collects the classes of all AssociationCollection classes, then pushes associations::HasManyThrough into the array and adds the paginate missing method to all subclasses. However, since 9200, HasManyThrough is now descendent from AssociationCollection, this is unnecessary and seems to cause a redundancy by adding a missing method the 2nd time.

    In order to make will_paginate work properly with projects running Rails versions before or after 9200, adding a call to .uniq before .each on line 44 seems to fix the problem.

    (collection.instance_methods.include?(:create!) ?

    collection : collection.subclasses.map(&:constantize)

    • ).push(associations::HasManyThroughAssociation).each do |klass| + ).push(associations::HasManyThroughAssociation).uniq.each do |klass|

    klass.class_eval do

    include Finder::ClassMethods

    I’ve just worked on this and testing is minimal, but it seems to be a 100% fix.

    April 3rd, 2008 @ 01:49 AM

  2. Geoff Garside
    Geoff Garside

    Thanks Aaron, my initial fix was a bit more simplistic (delete the .push) but yours is much cleaner. Its always a terrible feeling of dread when you update vendor/ run your tests and loads of things go wrong.

    April 3rd, 2008 @ 03:23 AM

  3. Martin Gamsjaeger (snusnu)
    Martin Gamsjaeger (snusnu)

    Hey guys,

    I can confirm that this fixed all my errors, although I found the offending line 44 in will_paginate.rb and not finder.rb ;-)

    Thx so much! You rock hard! 4hours! Awesome ;)!

    cheers

    Martin Gamsjaeger

    April 3rd, 2008 @ 04:09 AM

  4. Mislav
    Mislav
    • State changed from new to resolved

    You love edge Rails? Then use edge will_paginate :)

    http://github.com/mislav/will_pa...

    April 4th, 2008 @ 04:19 AM

  5. Mislav
    Mislav
    • Assigned user changed from Chris Wanstrath to Mislav

    OK, I lied. But now it's resolved properly http://github.com/mislav/will_pa...

    April 5th, 2008 @ 06:06 AM

  6. wildchild
    wildchild

    Broken again (SystemStackError: stack level too deep) after AR associations refactoring (r9233) :(

    April 6th, 2008 @ 08:03 AM

  7. Mislav

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.