I have two partials which refer to one another. When I calculate nested dependencies in the console likes so (with some debug code outputting which template is being loaded):
finder = ApplicationController.new.lookup_context
ActionView::Digestor.new(name: "posts/show", finder: finder).nested_dependencies
or via the rake task like so:
rake cache_digests:nested_dependencies TEMPLATE=posts/show
I get a short list of initial dependencies, and then this in an infinite loop, until the ruby stack is full:
...
>>>>>>> users/foo
>>>>>>> users/bar
>>>>>>> users/baz
>>>>>>> users/bip
>>>>>>> users/foo
>>>>>>> users/bar
>>>>>>> users/baz
>>>>>>> users/bip
SystemStackError: stack level too deep
(template names changed)
However, when I run the app server and request the template, things run just fine, no infinite loops.
Here are my settings in all of the above cases:
config.action_controller.perform_caching = true
config.cache_store = :file_store, Rails.root.to_s + '/tmp/cache/stuff'
ActionView::Base.cache_template_loading = true
The code indicates that it does have recursive reference protection: https://github.com/rails/rails/blob/v4.1.8/actionview/lib/action_view/digestor.rb#L35
Why is this protection working in the server environment but not in console or the rake task?
(also a github issue https://github.com/rails/rails/issues/18667 )
ActionView::Digestor.digest
which calls intocompute_and_store_digest
which has the inifite loop protection. Howevernested_dependencies
only callsDependencyTracker.find_dependencies
recursively without any infinite loop detection. If you check for usages ofnested_dependencies
on github you can see that it is only used from the rake task and nowhere else. So IMHO this is a bug innested_dependencies
. – Priggish