SystemStackError: stack level too deep

0 Min. Read
Aug 14, 2019

Background

Today I encountered with the following error. I didn’t know what might be the cause of this error.

Expected Culprit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
SystemStackError in DashboardsController#show
stack level too deep

Extracted source (around line #11):

    else
      > @questions = current_organization.questions.in_dashboard
        @subjects  = current_organization.subjects.in_dashboard
    end
  end

Rails.root: /Users/john/projects/lgprofile

Application Trace | Framework Trace | Full Trace
app/controllers/dashboards_controller.rb:11:in `show'

The code in line no#11 looks fine to me. It wasn’t changed in a few days. This should not be the cause. I then checked the associations. May be something changed and is causing this error. I found no changes in the model association code.

While going through the git diff I saw some new line in model like

Real Culprit

1
  +  scope :parents, -> { where(question_id: nil) }

When I commented this code, the app started running again.

Reason behind this error