1

Mongoid2.0.0.rc7から移行されたMongoid2.2.0で、モデルのインスタンスを保存すると、rc7では発生しなかったスタックレベルの非常に深い例外が発生します。

これが私のモデルです。とてもシンプルです。

class Firm
  include Mongoid::Document
  references_many :accounts, :autosave => true
end

class Account
  include Mongoid::Document
  field :name, :type => String
  referenced_in :firm, :autosave => true
end

サンプルコードは次のとおりです。

firm = Firm.create! :name=>'XYZ'
acc = Account.create! :name=>"Hello", :firm=>firm

例外がスローされますAccount.create!

アカウントを作成すると、膨大なスタックトレースが生成されます。

SystemStackError: stack level too deep
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_103'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_67'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_67'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_103'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_103'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_67'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_67'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_103'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_103'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_67'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_67'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_103'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_103'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_67'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_67'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_103'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_103'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_67'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_67'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_103'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_103'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_67'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_67'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_103'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_103'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_67'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_67'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:29:in `_callback_after_103'
    org/jruby/RubyArray.java:1615:in `each'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/relations/auto_save.rb:28:in `_callback_after_103'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:429:in `_run_save_callbacks'
    org/jruby/RubyBasicObject.java:1698:in `__send__'
    org/jruby/RubyKernel.java:2097:in `send'
    /home/x/.rvm/gems/jruby-1.6.7/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:93:in `run_callbacks'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/modification.rb:23:in `prepare'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence/operations/update.rb:43:in `persist'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:86:in `update'
    /home/x/.rvm/gems/jruby-1.6.7/gems/mongoid-2.2.0/lib/mongoid/persistence.rb:151:in `upsert'

autosave1つのモデルでのみ定義する必要がありますか?私がそうするなら、それはうまくいくようです。両方のモデルに自動保存を入れると無限ループになる理由は理解していますが、正しい解決策は何ですか?

4

0 に答える 0