Stack level too deep

I am getting following error:

SystemStackError in Database#index

Showing layouts/application.rhtml where line #90 raised:

stack level too deep

Interesting thing is that this only occurs when I run the application
in development mode. While running in test and production modes, there
is no error.

Can any body guide me where the problem might be?


I know its noisy, but I am placing the stack trace for reference here:

====== STACK TRACE STARTS =========
193:in method_missing' vendor/rails/activerecord/lib/active_record/attribute_methods.rb: 194:inmethod_missing’
association_proxy.rb:125:in each' vendor/rails/activerecord/lib/active_record/associations/ association_proxy.rb:125:insend’
association_proxy.rb:125:in method_missing' vendor/rails/activerecord/lib/active_record/associations/ association_collection.rb:162:inmethod_missing’
vendor/rails/actionpack/lib/action_view/base.rb:637:in send' vendor/rails/actionpack/lib/action_view/base.rb:637:incompile_and_render_template’
render_template' vendor/rails/actionpack/lib/action_view/base.rb:316:inrender_file’
render_without_benchmark' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:51:inrender’
/usr/lib/ruby/1.8/benchmark.rb:293:in measure' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:51:inrender’
default_render' vendor/rails/actionpack/lib/action_controller/base.rb:1159:inperform_action_without_filters’
call_filters' vendor/rails/actionpack/lib/action_controller/filters.rb:689:inperform_action_without_benchmark’
perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:inmeasure’
perform_action_without_rescue' vendor/rails/actionpack/lib/action_controller/rescue.rb:199:inperform_action_without_caching’
perform_action' vendor/rails/activerecord/lib/active_record/connection_adapters/ abstract/query_cache.rb:33:incache’
cache' vendor/rails/actionpack/lib/action_controller/caching.rb:677:inperform_action’
vendor/rails/actionpack/lib/action_controller/base.rb:524:in send' vendor/rails/actionpack/lib/action_controller/base.rb:524:inprocess_without_filters’
process_without_session_management_support' vendor/rails/actionpack/lib/action_controller/session_management.rb: 123:inprocess’
vendor/rails/actionpack/lib/action_controller/base.rb:388:in process' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:171:inhandle_request’
dispatch' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:126:indispatch_cgi’
dispatch' vendor/rails/railties/lib/webrick_server.rb:112:inhandle_dispatch’
vendor/rails/railties/lib/webrick_server.rb:78:in service' /usr/lib/ruby/1.8/webrick/httpserver.rb:104:inservice’
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in run' /usr/lib/ruby/1.8/webrick/server.rb:173:instart_thread’
/usr/lib/ruby/1.8/webrick/server.rb:162:in start' /usr/lib/ruby/1.8/webrick/server.rb:162:instart_thread’
/usr/lib/ruby/1.8/webrick/server.rb:95:in start' /usr/lib/ruby/1.8/webrick/server.rb:92:ineach’
/usr/lib/ruby/1.8/webrick/server.rb:92:in start' /usr/lib/ruby/1.8/webrick/server.rb:23:instart’
/usr/lib/ruby/1.8/webrick/server.rb:82:in start' vendor/rails/railties/lib/webrick_server.rb:62:indispatch’
gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
require' vendor/rails/activesupport/lib/active_support/dependencies.rb:342:innew_constants_in’
require' vendor/rails/railties/lib/commands/server.rb:39 script/server:3:inrequire’
====== STACK TRACE ENDS ==========

What’s on line 90 of application.rhtml?

On Fri, May 16, 2008 at 8:16 PM, MohsinHijazee [email protected]

Interesting thing is that this only occurs when I run the application
====== STACK TRACE STARTS =========
abstract/query_cache.rb:33:in cache' 123:inprocess’
vendor/rails/railties/lib/webrick_server.rb:78:in service' vendor/rails/railties/lib/webrick_server.rb:62:indispatch’
require' vendor/rails/railties/lib/commands/server.rb:39 script/server:3:inrequire’
====== STACK TRACE ENDS ==========

Ryan B.
Feel free to add me to MSN and/or GTalk as this email.

On May 16, 3:51 pm, “Ryan B. (Radar)” [email protected]

What’s on line 90 of application.rhtml?

Here are the affected lines:

90: <img
%= ([email protected]? and ( ? “collapse.gif” : “expand.gif”%>"
border=“0” id=“img< %>”>

91: <%=link_to_unless_current(t(,{:scope =>
‘account’}),{ :controller=> “/database”, :action
=>“list_entities”, :id =>},{ :title =>
t(“madb_database_menu_link_title”)} )%>
93: <%=link_to(image_tag(“icon/small/search.gif”, :size =>
“9x9”, :border =>0, :alt => t(“madb_search”)), { :controller => “/
search”, :database_id =>}, { :title=> t(“madb_search”)}) %>

And the perfectly work fine in test and production modes.

On May 16, 4:00 pm, MohsinHijazee [email protected] wrote:

“9x8”, :border =>0), :controller => “javascript(change’’)”) %>–>
search", :database_id =>}, { :title=> t(“madb_search”)}) %>

And the perfectly work fine in test and production modes.

Well the issue this:
When <%= -%>
This causes SystemStackError exception to be raised even in debugger.
I mean if I do this in the debugger:

Then an exception of SystemStackError is reported. I further traced
the problem into rails and in the ActiveRecord::AttributeMethods,
(file attive_record/lib/attribute_methods.rb line 194)

Allows access to the object attributes, which are held in the

@attributes hash, as though they
174 # were first-class methods. So a Person class with a name
attribute can use Person#name and
175 # Person#name= and never directly use the attributes hash –
except for multiple assigns with
176 # ActiveRecord#attributes=. A Milestone class can also ask
Milestone#completed? to test that
177 # the completed attribute is not nil or 0.
178 #
179 # It’s also possible to instantiate related objects, so a
Client class belonging to the clients
180 # table with a master_id foreign key can instantiate master
through Client#master.
181 def method_missing(method_id, *args, &block)
182 method_name = method_id.to_s
184 # If we haven’t generated any methods yet, generate them,
185 # see if we’ve created the method we’re looking for.
186 if !self.class.generated_methods?
187 self.class.define_attribute_methods
188 if self.class.generated_methods.include?(method_name)
189 return self.send(method_id, *args, &block)
190 end
191 end
193 if self.class.primary_key.to_s == method_name
194 id
195 elsif md = self.class.match_attribute_method?(method_name)
196 attribute_name, method_type = md.pre_match, md.to_s
197 if @attributes.include?(attribute_name)
198 send(“attribute#{method_type}”, attribute_name,
*args, &block)
199 else
200 super
201 end
202 elsif @attributes.include?(method_name)
203 read_attribute(method_name)
204 else
205 super
206 end
207 end

Look at line number 193 and 194. Because id method is not defined
(neither its generated by the generate_attribute_methods) id is called
again which gives rise to another invocation of method_missing and
which in turn again… So this is an infinite recursions which causes
the SystemStackError to occur.

  • Now the issue is that why does not this problem occur in test and
    production environments?
  • And if its an active record bug, then in what circumstances it
    occurs? I’m not sure how to simulate this bug except where its
    occurring now.

On May 16, 4:00 pm, MohsinHijazee [email protected] wrote:

“9x8”, :border =>0), :controller => “javascript(change’’)”) %>–>
search", :database_id =>}, { :title=> t(“madb_search”)}) %>

And the perfectly work fine in test and production modes.

Well friends!
Problem is over. Its a Rails 2.02 bug and when I discovered it, I
also found that its already reported by many others at:

The first ticket describes the situation exactly as it was

investigated by us. The workaround mentioned in the ticket did not
work for us. The first ticket mentions following reasons for it:

* When you access models through associations.
* And in development.rb, you have config.cache_classes=false
* While accessing the id attribute for the first time, it does not

occur but on each subsequent call, it occurs till the server is
* Other people also faced this problem on Rails 2.02 with SQLite
and MySQL on Mac OS X and Windows

We are on following configurations:

  • ruby 1.86
  • Rails 2.02
  • Ubuntu 7.04
  • PostgreSQL 8.2

I can provide the application stack trace also.
The ticket at rubydev is updated by me.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs