ActiveRecord::Associations::AssociationCollection#any? broken since rails-rev9199
Reported by Martin Gamsjaeger (snusnu) | April 2nd, 2008 @ 10:08 PM
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
Comments and changes to this ticket
-
Aaron H. April 3rd, 2008 @ 01:49 AM
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.
-
Geoff Garside April 3rd, 2008 @ 03:23 AM
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.
-
Martin Gamsjaeger (snusnu) April 3rd, 2008 @ 04:09 AM
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
-
Mislav April 4th, 2008 @ 04:19 AM
- State changed from new to resolved
You love edge Rails? Then use edge will_paginate :)
-
Mislav April 5th, 2008 @ 06:06 AM
- Assigned user changed from Chris Wanstrath to Mislav
OK, I lied. But now it's resolved properly http://github.com/mislav/will_pa...
-
wildchild April 6th, 2008 @ 08:03 AM
Broken again (SystemStackError: stack level too deep) after AR associations refactoring (r9233) :(
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
Everyone's favorite Ruby library for pagination of practically anything!
People watching this ticket
Referenced by
- 197 using :param_name => "something[page]" leads to invalid behavior Closes #197, #218, #216, #204 https://github.com/mislav/w...