closure_tree icon indicating copy to clipboard operation
closure_tree copied to clipboard

SystemStackError when updating fixtures

Open wakairo opened this issue 2 years ago • 1 comments

In rails test, the following test code causes an error: SystemStackError: stack level too deep.

    node = nodes(:one)
    node.update(parent_id: node.id)

Node (class of the node) has closure tree as below.

class Node < ApplicationRecord
  has_closure_tree
end

It seems that the following conditions are needed to reproduce this error:

  • The node object is made from fixtures.
  • Updating parent_id of the node to an id of self or descendants.

I have made a repository for this issue. To reproduce this error on this repository, please execute rails test command.

Repository: https://github.com/wakairo/issue-closure_tree-error_on_update

wakairo avatar Sep 28 '23 02:09 wakairo

To work around this, you could try to either put the node_hierarchies table into fixtures as well, or call Node.rebuild! after fixtures are loaded but before tests are run.

jkraemer avatar Nov 21 '23 03:11 jkraemer