<?xml version="1.0" encoding="UTF-8"?>
<ticket>
  <assigned-user-id type="integer" nil="true"></assigned-user-id>
  <attachments-count type="integer">0</attachments-count>
  <closed type="boolean">true</closed>
  <created-at type="datetime">2008-08-07T16:55:44+01:00</created-at>
  <creator-id type="integer">28407</creator-id>
  <milestone-due-on type="datetime" nil="true"></milestone-due-on>
  <milestone-id type="integer">9903</milestone-id>
  <number type="integer">774</number>
  <permalink>stack-error-in-method-missing</permalink>
  <priority type="integer">235</priority>
  <project-id type="integer">8994</project-id>
  <raw-data type="binary" nil="true" encoding="base64"></raw-data>
  <state>invalid</state>
  <tag>2.1 2.3.4 activerecord edge</tag>
  <title>Stack Error in method missing</title>
  <updated-at type="datetime">2009-12-16T13:06:24+00:00</updated-at>
  <user-id type="integer">43238</user-id>
  <user-name>Marek Goldmann</user-name>
  <creator-name>jshumate</creator-name>
  <url>http://rails.lighthouseapp.com/projects/8994/tickets/774</url>
  <milestone-title>2.x</milestone-title>
  <original-body>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 method_missing(method_id, *args, &amp;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, &amp;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__(&quot;attribute#{method_type}&quot;, attribute_name, *args, &amp;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.</original-body>
  <latest-body>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 method_missing(method_id, *args, &amp;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, &amp;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__(&quot;attribute#{method_type}&quot;, attribute_name, *args, &amp;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.</latest-body>
  <original-body-html>&lt;div&gt;&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;def method&lt;em&gt;missing(method&lt;/em&gt;id, *args, &amp;amp;block)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  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, &amp;amp;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__(&quot;attribute#{method_type}&quot;, attribute_name, *args, &amp;amp;block)
    else
      super
    end
  elsif @attributes.include?(method_name)
    read_attribute(method_name)
  else
    super
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It only seems to happen when looking up 'id' and the loop is happening on the line.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  if self.class.primary_key.to_s == method_name
    id
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;where the call to id causes an infinite loop on method_missing.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;I will work to find a simple example case, but wanted to post this in case someone else with more experience has some suggestions.&lt;/p&gt;&lt;/div&gt;</original-body-html>
  <versions type="array">
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>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 method_missing(method_id, *args, &amp;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, &amp;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__(&quot;attribute#{method_type}&quot;, attribute_name, *args, &amp;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.</body>
      <body-html>&lt;div&gt;&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;def method&lt;em&gt;missing(method&lt;/em&gt;id, *args, &amp;amp;block)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  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, &amp;amp;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__(&quot;attribute#{method_type}&quot;, attribute_name, *args, &amp;amp;block)
    else
      super
    end
  elsif @attributes.include?(method_name)
    read_attribute(method_name)
  else
    super
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It only seems to happen when looking up 'id' and the loop is happening on the line.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  if self.class.primary_key.to_s == method_name
    id
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;where the call to id causes an infinite loop on method_missing.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;I will work to find a simple example case, but wanted to post this in case someone else with more experience has some suggestions.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-07T16:55:45+01:00</created-at>
      <creator-id type="integer">28407</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">774</number>
      <permalink>stack-error-in-method-missing</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>2.1 activerecord edge</tag>
      <title>Stack Error in method missing</title>
      <updated-at type="datetime">2008-08-07T16:55:45+01:00</updated-at>
      <user-id type="integer">28407</user-id>
      <user-name>jshumate</user-name>
      <creator-name>jshumate</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/774</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>I replaced the call to id on line 245 with read_attribute('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 method_missing.

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.</body>
      <body-html>&lt;div&gt;&lt;p&gt;I replaced the call to id on line 245 with read&lt;em&gt;attribute('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 method&lt;/em&gt;missing.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-07T18:32:09+01:00</created-at>
      <creator-id type="integer">28407</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">774</number>
      <permalink>stack-error-in-method-missing</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>2.1 activerecord edge</tag>
      <title>Stack Error in method missing</title>
      <updated-at type="datetime">2008-08-07T18:32:09+01:00</updated-at>
      <user-id type="integer">28407</user-id>
      <user-name>jshumate</user-name>
      <creator-name>jshumate</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/774</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>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.</body>
      <body-html>&lt;div&gt;&lt;p&gt;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.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-08-09T16:52:17+01:00</created-at>
      <creator-id type="integer">28407</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">774</number>
      <permalink>stack-error-in-method-missing</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>2.1 activerecord edge</tag>
      <title>Stack Error in method missing</title>
      <updated-at type="datetime">2008-08-09T16:52:17+01:00</updated-at>
      <user-id type="integer">28407</user-id>
      <user-name>jshumate</user-name>
      <creator-name>jshumate</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/774</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>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.</body>
      <body-html>&lt;div&gt;&lt;p&gt;I too am having this problem with Rails 2.1 in connection with
using rails engines.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;I have not dug into this yet, but thought that it might be
useful to mention.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-09-10T15:45:20+01:00</created-at>
      <creator-id type="integer">28407</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">774</number>
      <permalink>stack-error-in-method-missing</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>2.1 activerecord edge</tag>
      <title>Stack Error in method missing</title>
      <updated-at type="datetime">2008-09-10T15:45:26+01:00</updated-at>
      <user-id type="integer">31606</user-id>
      <user-name>jfoxny</user-name>
      <creator-name>jshumate</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/774</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>See also http://dev.rubyonrails.org/ticket/10896
I get this as well--engines + 2.1
Thanks!
-=R</body>
      <body-html>&lt;div&gt;&lt;p&gt;See also &lt;a href=&quot;http://dev.rubyonrails.org/ticket/10896&quot;&gt;http://dev.rubyonrails.org/ticke...&lt;/a&gt;
I get this as well--engines + 2.1 Thanks! -=R&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">false</closed>
      <created-at type="datetime">2008-12-16T21:07:16+00:00</created-at>
      <creator-id type="integer">28407</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">774</number>
      <permalink>stack-error-in-method-missing</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>new</state>
      <tag>2.1 activerecord edge</tag>
      <title>Stack Error in method missing</title>
      <updated-at type="datetime">2008-12-16T21:07:21+00:00</updated-at>
      <user-id type="integer">18996</user-id>
      <user-name>Roger</user-name>
      <creator-name>jshumate</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/774</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>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/contributing_to_rails.html should help :)

Thanks.</body>
      <body-html>&lt;div&gt;&lt;p&gt;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 ! &lt;a href=&quot;http://guides.rails.info/contributing_to_rails.html&quot;&gt;http://guides.rails.info/contrib...&lt;/a&gt;
should help :)&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-03-08T17:06:44+00:00</created-at>
      <creator-id type="integer">28407</creator-id>
      <diffable-attributes type="yaml">--- 
:state: new
</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">774</number>
      <permalink>stack-error-in-method-missing</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>invalid</state>
      <tag>2.1 activerecord edge</tag>
      <title>Stack Error in method missing</title>
      <updated-at type="datetime">2009-03-08T17:06:48+00:00</updated-at>
      <user-id type="integer">1366</user-id>
      <user-name>Pratik</user-name>
      <creator-name>jshumate</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/774</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>Yes! I'm still encountering this problem!
mmmm...I'll try to submit a failing something over the weekend.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Yes! I'm still encountering this problem!&lt;br&gt;
mmmm...I'll try to submit a failing something over the weekend.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-09-11T19:55:58+01:00</created-at>
      <creator-id type="integer">28407</creator-id>
      <diffable-attributes type="yaml">--- {}

</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">774</number>
      <permalink>stack-error-in-method-missing</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>invalid</state>
      <tag>2.1 activerecord edge</tag>
      <title>Stack Error in method missing</title>
      <updated-at type="datetime">2009-09-11T20:04:44+01:00</updated-at>
      <user-id type="integer">60216</user-id>
      <user-name>btelles</user-name>
      <creator-name>jshumate</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/774</url>
      <milestone-title>2.x</milestone-title>
    </version>
    <version type="Ticket::Version">
      <assigned-user-id type="integer" nil="true"></assigned-user-id>
      <attachments-count type="integer">0</attachments-count>
      <body>Same issue here with Rails and AR 2.3.4.</body>
      <body-html>&lt;div&gt;&lt;p&gt;Same issue here with Rails and AR 2.3.4.&lt;/p&gt;&lt;/div&gt;</body-html>
      <closed type="boolean">true</closed>
      <created-at type="datetime">2009-12-16T13:06:21+00:00</created-at>
      <creator-id type="integer">28407</creator-id>
      <diffable-attributes type="yaml">--- 
:tag: 2.1 activerecord edge
</diffable-attributes>
      <milestone-id type="integer">9903</milestone-id>
      <number type="integer">774</number>
      <permalink>stack-error-in-method-missing</permalink>
      <priority type="integer">0</priority>
      <project-id type="integer">8994</project-id>
      <state>invalid</state>
      <tag>2.1 2.3.4 activerecord edge</tag>
      <title>Stack Error in method missing</title>
      <updated-at type="datetime">2009-12-16T13:06:24+00:00</updated-at>
      <user-id type="integer">43238</user-id>
      <user-name>Marek Goldmann</user-name>
      <creator-name>jshumate</creator-name>
      <url>http://rails.lighthouseapp.com/projects/8994/tickets/774</url>
      <milestone-title>2.x</milestone-title>
    </version>
  </versions>
</ticket>
