debugging stack level too deep error on rails

Sep 01, 2016 - Prakash Murthy

Ran into a stack level too deep error while running rake db:seed on a client rails application I am upgrading from rails 3.2.

Rails

There wasn't much of a stack trace any where to help figure out the root cause of this problem, making my thoughts to be exactly what Captain Picard is saying here:

Rails

Thankfully, found this useful gist through a Stackoverflow answer that saved the day. And helped me learn something new.

Steps for tracing a SystemStackError when there is no stack trace

  1. Create a trace.rb file with the following content, and place it in the ./config/initializers folder in the Ruby on Rails app:
  2. Perform the action that is causing the stack level too deep error message.
  3. The full stack trace will be dumped in the trace.txt file in the root directory of the Rails app.
  4. Look through the file, and profit.

In this specific case, it turned out that the associated model for the seed file that was causing the error was defining a named_scope with name :all. This is a problem when upgrading from Rails 3.x to Rails 4.x because Rails 4.x defines the all scope by default.

Back to Blog