Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-5658

"cascade_callbacks" results in SystemStackError with many documents

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 9.0.0, 8.0.7, 8.1.3
    • Affects Version/s: 8.0.1, 8.1.0, 8.0.2, 8.0.3, 8.0.4, 8.0.5, 8.1.1, 8.0.6, 8.1.2
    • Component/s: Associations
    • None

      Attempting to save a new document with a large number of embedded documents fails with a SystemStackError when the has_many association has cascade_callbacks: true. Here's a quick example:

      class Foo
        include Mongoid::Document
      
        embeds_many :bars, cascade_callbacks: true
      end
      
      class Bar
        include Mongoid::Document
      
        embedded_in :foo
      end
      
      foo = Foo.new
      1500.times { foo.bars.build }
      foo.save # SystemStackError: stack level too deep
      

      The limit seems to be 1,117 embedded documents.

      The problem was introduced in Mongoid 8. The above code works just fine with Mongoid 7.

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            mail@stefanschuessler.de Stefan Schüßler
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: