How to get a backtrace from a SystemStackError: stack level too deep?
Apparently this was tracked as feature 6216 and fixed in Ruby 2.2.
$ ruby system-stack-error.rb
system-stack-error.rb:6:in `bar': stack level too deep (SystemStackError)
from system-stack-error.rb:2:in `foo'
from system-stack-error.rb:10:in `baz'
from system-stack-error.rb:6:in `bar'
from system-stack-error.rb:2:in `foo'
from system-stack-error.rb:10:in `baz'
from system-stack-error.rb:6:in `bar'
from system-stack-error.rb:2:in `foo'
from system-stack-error.rb:10:in `baz'
... 10067 levels...
from system-stack-error.rb:10:in `baz'
from system-stack-error.rb:6:in `bar'
from system-stack-error.rb:2:in `foo'
from system-stack-error.rb:13:in `<main>'
Can the origin of SystemStackError: stack level too deep be identified without a full stack trace?
In this situation, I;d use "printf debugging". Add log.info "got to here 1"
(2, 3 ,4 etc) in various points in your controller and template code.
Then reproduce the error.
Then check the logs and see which statements did/didn't get logged - and therefore which part of the code you didn't get to and if any parts repeated endlessly...
and you've at least narrowed down to which part of the code is the problem.
Calabash-iOS : stack level too deep (SystemStackError) error is encountered each time an assertion is failing
I believe you are calling include Calabash::Cucumber::Operations
somewhere. You should not need to include
Operations anywhere in your code.
SystemStackError - Stack Level Too Deep
It is due to your model name and/or controller action name (Request
and request
). These are kind of reserved words in Rails.
Arel: I get stack level too deep error when I try to get SQL from Arel
Now that I understand the desired output here is how I would go about this
class Report
JOB_STATS = Arel::Table.new('jobstat_jobs')
CORE_MEMBERS = Arel::Table.new('core_members')
SESSIONS = Arel::Table.new('sessions_projects_in_sessions')
def additions
# This could be ported too if I knew the tables for end_time, start_time, and num_nodes
{
node_hours: Arel.sql("((extract(epoch from (end_time - start_time))/ 3600))*num_nodes").sum,
jobs: JOB_STATS[:id].count
}
end
def n
@n ||= _base_query.as('n')
end
def s
@s ||= _base_query
.project(JOB_STATS[:state])
.group(JOB_STATS[:state]).as('s')
end
def alias_columns
additions.keys.flat_map do |key|
[s[key].as("s_#{key}"),
n[key].as("n_#{key}"),
(s[key] / n[key]).as("share_#{key}")]
end
end
def query
Arel::SelectManager.new.project(
s[:project_id].as('id'),
s[:state],
*alias_columns
)
.from(s)
.join(n).on(s[:project_id].eq(n[:project_id]))
end
def to_sql
query.to_sql
end
private
def cast_as_decimal(value,alias_name:)
Arel::Nodes::NamedFunction.new(
"CAST",
[Arel::Nodes::As.new(value, Arel.sql('DECIMAL'))]
).as(alias_name.to_s)
end
def _base_query
JOB_STATS
.project(
CORE_MEMBERS[:project_id],
*additions.map {|k,v| cast_as_decimal(v, alias_name: k)})
.join(CORE_MEMBERS).on(CORE_MEMBERS[:login].eq(JOB_STATS[:login]))
.outer_join(SESSIONS).on(SESSIONS[:project_id].eq(CORE_MEMBERS[:project_id]))
.where(JOB_STATS[:state].not_in(['COMPLETETED', 'RUNNING', 'unknown']))
.group(CORE_MEMBERS[:project_id])
end
end
Result of Report.new.to_sql
SELECT
s."project_id" AS id,
s."state",
s."node_hours" AS s_node_hours,
n."node_hours" AS n_node_hours,
s."node_hours" / n."node_hours" AS share_node_hours,
s."jobs" AS s_jobs,
n."jobs" AS n_jobs,
s."jobs" / n."jobs" AS share_jobs
FROM
(
SELECT
"core_members"."project_id",
CAST(SUM(((extract(epoch from (end_time - start_time))/ 3600))*num_nodes) AS DECIMAL) AS node_hours,
CAST(COUNT("jobstat_jobs"."id") AS DECIMAL) AS jobs,
"jobstat_jobs"."state"
FROM
"jobstat_jobs"
INNER JOIN "core_members" ON "core_members"."login" = "jobstat_jobs"."login"
LEFT OUTER JOIN "sessions_projects_in_sessions" ON "sessions_projects_in_sessions"."project_id" = "core_members"."project_id"
WHERE
"jobstat_jobs"."state" NOT IN (N'COMPLETETED', N'RUNNING', N'unknown')
GROUP BY
"core_members"."project_id",
"jobstat_jobs"."state"
) s
INNER JOIN (
SELECT
"core_members"."project_id",
CAST(SUM(((extract(epoch from (end_time - start_time))/ 3600))*num_nodes) AS DECIMAL) AS node_hours,
CAST(COUNT("jobstat_jobs"."id") AS DECIMAL) AS jobs
FROM
"jobstat_jobs"
INNER JOIN "core_members" ON "core_members"."login" = "jobstat_jobs"."login"
LEFT OUTER JOIN "sessions_projects_in_sessions" ON "sessions_projects_in_sessions"."project_id" = "core_members"."project_id"
WHERE
"jobstat_jobs"."state" NOT IN (N'COMPLETETED', N'RUNNING', N'unknown')
GROUP BY
"core_members"."project_id"
) n ON s."project_id" = n."project_id"
This will also allow you further filter the resulting query like so:
rpt = Report.new
q = rpt.query.where(rpt.n[:jobs].gt(12))
q.to_sql
#=> "...same as above...WHERE n.\"jobs\" > 12"
Rspec Failure/Error: stack level too deep
Both of your serializers have a has_one/has_many relationship. Because of this, each depends on the other table to determine which object(s) is associated with it, causing a stack overflow.
Instead of having a has_one :user
in the product serializer, change it to belongs_to :user
Related Topics
Array of Indexes to Array of Ranges
Rails: Encoding Woes with Serialized Hashes Despite Utf8
How to Read Whole File in Ruby
HTML Code Inside Buttons with Simple_Form
Rspec Failing Error: Expected False to Respond to 'False'
Override Rails Helpers with Access to Original
How to Extract the Code from a Proc Object
How to Format Irb Command Prompt
Ruby | Find a Way to Find an Exception on the Same Word to Capitalize
How to Drop Columns Using Rails Migration
How to Convert a String to Lower or Upper Case in Ruby