rake 0.8.7 db:migrate或db:种子运行时错误,"堆栈级别太深"

时间:2013-06-26 16:40:26

标签: ruby-on-rails ruby rake stack-overflow

  • Rake 0.8.7
  • Rails 2.3.18
  • RubyGems 1.7.2

我查看了类似的问题,但这里不适用:

  • 在任务中没有进行任何递归
  • 不使用Bundler或RVM(如果使用bundler是解决方案,那么我就搞砸了)
  • 不包括ActionView :: Helpers
  • 未使用名为scrubyt的宝石
  • 更改代码以使用事务无法解决问题。

Braindead简单行更新。如果我将其作为迁移或种子运行,结果相同。

class AddValuesForPlanApiQuotaDaily < ActiveRecord::Migration
  def self.up

    p = Plan.find(10)
    p.api_quota_daily = 3000
    p.save!

  end
end

或者来自db / seeds.rb:

p = Plan.find(10)

if p.api_quota_daily.nil?

    p.api_quota_daily = 3000
    p.save!

end

结果:

$ rake db:seed --trace
** Invoke db:seed (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:seed
rake aborted!
stack level too deep

跟踪:

/home/fun/dev/company/project/vendor/plugins/deadlock_retry/lib/deadlock_retry.rb:45:in `transaction_without_deadlock_handling'
/home/fun/dev/company/project/vendor/plugins/deadlock_retry/lib/deadlock_retry.rb:45:in `transaction'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.18/lib/active_record/transactions.rb:200:in `save!'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.18/lib/active_record/transactions.rb:208:in `rollback_active_record_state!'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.18/lib/active_record/transactions.rb:200:in `save!'
/home/fun/dev/company/project/db/seeds.rb:8
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.18/lib/active_support/dependencies.rb:171:in `load_without_new_constant_marking'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.18/lib/active_support/dependencies.rb:171:in `load'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.18/lib/active_support/dependencies.rb:547:in `new_constants_in'
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.18/lib/active_support/dependencies.rb:171:in `load'
/usr/lib/ruby/gems/1.8/gems/rails-2.3.18/lib/tasks/databases.rake:211
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19

无法升级rake或开始为此项目使用bundler。

3 个答案:

答案 0 :(得分:2)

另一个实际上是单词的选项,在迁移中使用原始SQL执行:

class AddValuesToPlanApiQuotas < ActiveRecord::Migration
  def self.up
  plan_id_api_limits = {
      10 => 3000,
      20 => 3000,
      30 => 5000,
      40 => 10000,
      50 => 20000,
      60 => 35000
    }
    plan_id_api_limits.each do |k,v|
      query = "UPDATE plans set api_quota_daily = #{v} where id=#{k}"
      ActiveRecord::Base.connection.execute(query);
    end
  end

end

我显然无法在0.8.7的rake迁移或种子任务中使用ActiveRecord

答案 1 :(得分:1)

不幸的是,我无法从经验中说出来,但我想知道这篇博客的内容是否可以帮到你:

http://dalibornasevic.com/posts/5-ruby-stack-level-too-deep-systemstackerror

基本上:

ulimit -a | grep 'stack size'

ulimit -s <some reasonably larger number>

希望有所帮助。

当然,我假设你是在类Unix系统上这样做的。

答案 2 :(得分:0)

这是一种可怕的做法,但我没有时间完成这项任务,今天也无法用耙子研究问题。

ruby script/runner db/seeds.rb

Ta da。