This SystemStackError is driving me crazy. It only takes place when testing with WEBrick - I can't reproduce it with any tests. It is caused by calling the "missing" id method (base.rb:2435) on my ActiveRecord class.
WEBrick and my tests are running as the same user, with a `ulimit -s` of 10240. Plus the query works sometimes so I don't think this matters.
Here's the trace:
/usr/lib/ruby/1.8/set.rb:93:in `empty?' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ attribute_methods.rb:64:in `generated_methods?' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ attribute_methods.rb:237:in `method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ attribute_methods.rb:245:in `method_missing' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2435:in `hash' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ association_preload.rb:13:in `uniq' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ association_preload.rb:13:in `preload_associations' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:1343:in `find_every' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:536:in `find' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ association_preload.rb:254:in `find_associated_records' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ association_preload.rb:154:in `preload_has_many_association' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ association_preload.rb:40:in `send' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ association_preload.rb:40:in `preload_one_association' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ association_preload.rb:38:in `each' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ association_preload.rb:38:in `preload_one_association' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ association_preload.rb:17:in `preload_associations' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ association_preload.rb:16:in `preload_associations' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ association_preload.rb:16:in `each' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ association_preload.rb:16:in `preload_associations' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:1343:in `find_every' /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:536:in `find' app/models/package.rb:29:in `search'
The thing is, sometimes it works -at first. And usually results in the trace ending before Set.empty? at: /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ attribute_methods.rb:64:in
Here's the relevant parts of my code:
class Package < ActiveRecord::Base has_many :deliveries, #,:select=>'id, user, host, delivered, region_id, package_id', :include=>:region, :dependent=>:delete_all
def self.search(criteria) raise ArgumentError, 'argument must be of type SearchCriteria' unless criteria.is_a\ ?(SearchCriteria) clause = build_search_where_clause(criteria) find(:all, :include=>[:deliveries], :conditions=>clause) end end
class Delivery < ActiveRecord::Base belongs_to :package belongs_to :region end
class Region < ActiveRecord::Base has_many :deliveries end
Looking at the SQL output, the exception is occurring after the :deliveries relation is queried. At first I though it was because I left out the id field from the has_many :deliveries, :select=>'...' But I commented it out and still no luck.
Any suggestions/ideas are greatly appreciated.