cache_digests icon indicating copy to clipboard operation
cache_digests copied to clipboard

Stack level too deep

Open satb opened this issue 12 years ago • 2 comments

See issue # 23 in which I was asked to open a new issue. This is still a problem.

Using JRuby 1.7.2 and rails 3.2.12. I am using the "closure_tree" gem that has some sort of recursion. Don't know if that is causing this.

SystemStackError - stack level too deep: org/jruby/RubyProc.java:261:in call' org/jruby/RubyProc.java:249:incall' org/jruby/RubyHash.java:681:in default' org/jruby/RubyHash.java:1070:in[]' (gem) actionpack-3.2.12/lib/action_view/template/resolver.rb:127:in query' org/jruby/RubyArray.java:2595:inreject!' org/jruby/RubyArray.java:2558:in reject' (gem) actionpack-3.2.12/lib/action_view/template/resolver.rb:126:inquery' (gem) actionpack-3.2.12/lib/action_view/template/resolver.rb:117:in find_templates' (gem) actionpack-3.2.12/lib/action_view/template/resolver.rb:46:infind_all' (gem) actionpack-3.2.12/lib/action_view/template/resolver.rb:77:in cached' (gem) actionpack-3.2.12/lib/action_view/template/resolver.rb:45:infind_all' (gem) actionpack-3.2.12/lib/action_view/path_set.rb:65:in find_all' org/jruby/RubyArray.java:1613:ineach' (gem) actionpack-3.2.12/lib/action_view/path_set.rb:64:in find_all' org/jruby/RubyArray.java:1613:ineach' (gem) actionpack-3.2.12/lib/action_view/path_set.rb:63:in find_all' (gem) actionpack-3.2.12/lib/action_view/path_set.rb:58:infind' (gem) actionpack-3.2.12/lib/action_view/lookup_context.rb:109:in find' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:79:insource' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:43:in digest' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:32:indigest' (gem) activesupport-3.2.12/lib/active_support/cache.rb:297:in fetch' (gem) activesupport-3.2.12/lib/active_support/cache.rb:520:ininstrument' (gem) activesupport-3.2.12/lib/active_support/cache.rb:296:in fetch' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:31:indigest' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:85:in dependency_digest' org/jruby/RubyArray.java:2348:incollect' org/jruby/RubyArray.java:2356:in collect' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:84:independency_digest' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:43:in digest' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:32:indigest' (gem) activesupport-3.2.12/lib/active_support/cache.rb:297:in fetch' (gem) activesupport-3.2.12/lib/active_support/cache.rb:520:ininstrument' (gem) activesupport-3.2.12/lib/active_support/cache.rb:296:in fetch' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:31:indigest' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:85:in dependency_digest' org/jruby/RubyArray.java:2348:incollect' org/jruby/RubyArray.java:2356:in collect' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:84:independency_digest' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:43:in digest' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:32:indigest' (gem) activesupport-3.2.12/lib/active_support/cache.rb:297:in fetch' (gem) activesupport-3.2.12/lib/active_support/cache.rb:520:ininstrument' (gem) activesupport-3.2.12/lib/active_support/cache.rb:296:in fetch' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:31:indigest' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:85:in dependency_digest' org/jruby/RubyArray.java:2348:incollect' org/jruby/RubyArray.java:2356:in collect' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:84:independency_digest' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:43:in digest' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:32:indigest' (gem) activesupport-3.2.12/lib/active_support/cache.rb:297:in fetch' (gem) activesupport-3.2.12/lib/active_support/cache.rb:520:ininstrument' (gem) activesupport-3.2.12/lib/active_support/cache.rb:296:in fetch' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:31:indigest' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:85:in dependency_digest' org/jruby/RubyArray.java:2348:incollect' org/jruby/RubyArray.java:2356:in collect' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:84:independency_digest' (gem) cache_digests-0.2.0/lib/cache_digests/template_digestor.rb:43:in `digest'

Not having issues if I remove "cache_digests". It works without causing the "stack too deep" problem with just fragment caching

application.html.erb has:

<% root_children = Category.root.children %>
                    <% cache "menu" do %>
                        <ul class="nav">
                          <% root_children.each do |c| %>
                            <%= render partial: "categories/menu", locals: {category: c} %>
                          <% end %>
                        </ul>
                    <% end %>

category/_menu.html.erb

<% if not (category.leaf?) %>
    <li class="dropdown">
      <a data-toggle="dropdown" class="dropdown-toggle" href="#"><%= category.name %><span class="caret"></span></a>
      <ul class="dropdown-menu">
        <li>
            <%= link_to "All #{pluralize("", category.name)}'", items_path(category_id: category)  %>
        </li>
        <% category.children.each do |c| %>
            <%= render partial: "categories/menu", locals: {category: c} %>
        <% end %>
      </ul>
    </li>
<% else %>
    <%= render partial: "categories/menu_item", locals: {category: category} %>
<% end %>

category/_menu_item.html.erb

<li>
  <%= link_to "#{category.name}", items_path(category_id: category) %>
</li>

satb avatar May 23 '13 03:05 satb

I have the same issue, using Rails 4.0.0. When I try to cache a segment with recursion, I get this error:

SystemStackError at /testing-webcast/sections
=============================================

> stack level too deep

activesupport (4.0.0) lib/active_support/notifications/instrumenter.rb, line 23

Here is the code from my app

models/section.rb

class Section < ActiveRecord::Base

    ...

    # Relations
    belongs_to :webcast
    belongs_to :speaker
    belongs_to :parent, class_name: Section
    has_many :children, class_name: Section, foreign_key: :parent_id

    # Scopes
    default_scope -> { order(:position) }
    scope :root, -> { where parent_id: nil }

    ....

end

sections/_webcast.html.erb

<% cache [ 'sections', sections.maximum(:updated_at).to_i ] do %>
    <%= render 'sections/list', sections: sections.root %>
<% end %>

sections/_list.html.erb

<ul>
    <% sections.each do |section| %>
        <li>
            <div class="section webcast animate">
                <h2><%= section.get_title %></h2>
            </div>

            <% if section.children.count > 0 %>
                <%= render 'sections/list', sections: section.children %>
            <% end %>
        </li>
    <% end %>
</ul>

Everything works, if I remove this part.

...
<% if section.children.count > 0 %>
    <%= render 'sections/list', sections: section.children %>
<% end %>
...

Other thing is that, after I remove the part from above, the cache is created. After this I add the part again to the template, remove the cache manually (delete the files) and it starts to work.

mupkoo avatar Oct 30 '13 10:10 mupkoo

Try this way...

<% if section.children.count > 0 %> <%= render sections: section.children, partial: 'sections/list' %> <% end %>

charles avatar Mar 13 '14 18:03 charles