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.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

Stack Error in method missing

#774

I began having a problem with stack level too deep errors at different locations in my application after moving to rails 2.1. The code always seems to work after a server restart, but will fail again sometime later and then fail consistently. It appears that it is looping in the following code in method missing.

def methodmissing(methodid, *args, &block)

  method_name = method_id.to_s

  # If we haven't generated any methods yet, generate them, then
  # see if we've created the method we're looking for.
  if !self.class.generated_methods?
    self.class.define_attribute_methods
    if self.class.generated_methods.include?(method_name)
      return self.send(method_id, *args, &block)
    end
  end

  if self.class.primary_key.to_s == method_name
    id
  elsif md = self.class.match_attribute_method?(method_name)
    attribute_name, method_type = md.pre_match, md.to_s
    if @attributes.include?(attribute_name)
      __send__("attribute#{method_type}", attribute_name, *args, &block)
    else
      super
    end
  elsif @attributes.include?(method_name)
    read_attribute(method_name)
  else
    super
  end
end

It only seems to happen when looking up 'id' and the loop is happening on the line.

  if self.class.primary_key.to_s == method_name
    id

where the call to id causes an infinite loop on method_missing.

I have tried this with 2.1 stable and edge with the same results and on both a windows and linux box with webrick and mongrel with the same results.

I will work to find a simple example case, but wanted to post this in case someone else with more experience has some suggestions.

Reported by jshumate · August 7th, 2008 @ 04:55 PM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. jshumate
    jshumate

    I replaced the call to id on line 245 with readattribute('id') and have not been able to get it to fail since. Not sure why id would become undefined during operation, but apparently it is and infinite loops on methodmissing.

    If someone with more knowledge could point me at a debugging technique that would get to the bottom of why this happens I am happy to try.

    August 7th, 2008 @ 06:32 PM

  2. jshumate
    jshumate

    With further digging this appears to be a symptom of the caching of objects on the second load during development that has been reported elsewhere.

    August 9th, 2008 @ 04:52 PM

  3. jfoxny
    jfoxny

    I too am having this problem with Rails 2.1 in connection with using rails engines.

    The fix that you described worked for me in most cases, however, today I've come across a new case now where, with the hack in-place, I receive a method missing error on a 2nd request a page. If I remove the hack, I receive the stack-overflow error that you described above.

    The method that I'm receiving the error on is in a brand new class (not an override of a class in the engine that I'm using). The new class does, however, reference classes that I've extended from the engine.

    I have not dug into this yet, but thought that it might be useful to mention.

    September 10th, 2008 @ 03:45 PM

  4. Roger
    Roger

    See also http://dev.rubyonrails.org/ticke... I get this as well--engines + 2.1 Thanks! -=R

    December 16th, 2008 @ 09:07 PM

  5. Pratik
    Pratik
    • State changed from new to invalid

    Is this still a problem ? I'll reopen if it is. Also, it'd be great if you could submit a failing test or a fix ! http://guides.rails.info/contrib... should help :)

    Thanks.

    March 8th, 2009 @ 05:06 PM

  6. btelles
    btelles

    Yes! I'm still encountering this problem!
    mmmm...I'll try to submit a failing something over the weekend.

    September 11th, 2009 @ 07:55 PM

  7. Deleted User
    Deleted User
    • Tag changed from 2.1, activerecord, edge to 2.1, 2.3.4, activerecord, edge

    Same issue here with Rails and AR 2.3.4.

    December 16th, 2009 @ 01:06 PM