This project is archived and is in readonly mode.

#774 ✓invalid

Stack Error in method missing

Reported by jshumate | August 7th, 2008 @ 04:55 PM | in 2.x

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?
    if self.class.generated_methods.include?(method_name)
      return self.send(method_id, *args, &block)

  if self.class.primary_key.to_s == method_name
  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)
  elsif @attributes.include?(method_name)

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

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.

Comments and changes to this ticket

  • jshumate

    jshumate August 7th, 2008 @ 06:32 PM

    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.

  • jshumate

    jshumate August 9th, 2008 @ 04:52 PM

    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.

  • jfoxny

    jfoxny September 10th, 2008 @ 03:45 PM

    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.

  • Roger

    Roger December 16th, 2008 @ 09:07 PM

    See also I get this as well--engines + 2.1 Thanks! -=R

  • Pratik

    Pratik March 8th, 2009 @ 05:06 PM

    • 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 ! should help :)


  • btelles

    btelles September 11th, 2009 @ 07:55 PM

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

  • Deleted User

    Deleted User December 16th, 2009 @ 01:06 PM

    • 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.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

Referenced by