{"record":{"id":"7059281ba216071b","repo":"ssssssss-team/spider-flow","slug":"parent-id-self-reference","errorCode":null,"errorMessage":"\" + parent.id + \": Self Reference","messagePattern":"\" \\+ parent\\.id \\+ \": Self Reference","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"spider-flow-web/src/main/resources/static/js/mxgraph/mxgraph.js","lineNumber":86860,"sourceCode":" *\r\n * Inserts the given cell into its parent and terminal cells.\r\n */\r\nmxCodec.prototype.insertIntoGraph = function(cell)\r\n{\r\n\tvar parent = cell.parent;\r\n\tvar source = cell.getTerminal(true);\r\n\tvar target = cell.getTerminal(false);\r\n\r\n\t// Fixes possible inconsistencies during insert into graph\r\n\tcell.setTerminal(null, false);\r\n\tcell.setTerminal(null, true);\r\n\tcell.parent = null;\r\n\t\r\n\tif (parent != null)\r\n\t{\r\n\t\tif (parent == cell)\r\n\t\t{\r\n\t\t\tthrow new Error(parent.id + ': Self Reference');\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tparent.insert(cell);\r\n\t\t}\r\n\t}\r\n\r\n\tif (source != null)\r\n\t{\r\n\t\tsource.insertEdge(cell, true);\r\n\t}\r\n\r\n\tif (target != null)\r\n\t{\r\n\t\ttarget.insertEdge(cell, false);\r\n\t}\r\n};\r\n\r","sourceCodeStart":86842,"sourceCodeEnd":86878,"githubUrl":"https://github.com/ssssssss-team/spider-flow/blob/c799cca99c7d064673dc79e6ef06a08bbc0e292d/spider-flow-web/src/main/resources/static/js/mxgraph/mxgraph.js#L86842-L86878","documentation":"When setting a cell's parent (mxGraphModel.parentForCellChanged), mxGraph rejects a cell being made its own parent, throwing Error(parent.id + ': Self Reference'). A cell that is its own ancestor would create a cycle in the model tree and break traversal/serialization.","triggerScenarios":"Calling model.add(parent, cell) or setting the parent where parent === cell; also occurs with group operations that compute the group incorrectly.","commonSituations":"Programmatic graph building where variables holding 'parent' and 'child' are swapped, group/ungroup code that includes the parent itself in the selection, drag-and-drop handlers dropping a cell onto itself.","solutions":["Check `parent !== cell` (and that parent is not a descendant of cell) before calling model.add.","Fix variable assignment so the target cell and parent cell are not confused.","In group operations, exclude the new parent node from the set of cells being reparented."],"exampleFix":"// before\nmodel.add(parent, cell); // parent may be cell itself\n// after\nif (parent != null && parent !== cell && !isDescendant(parent, cell)) {\n  model.add(parent, cell);\n}","handlingStrategy":"validation","validationCode":"function canReparent(parent, cell) {\n  return parent != null && parent !== cell && !isAncestor(cell, parent); // mxCell.isAncestor exists\n}","typeGuard":null,"tryCatchPattern":"try {\n  model.add(parent, cell);\n} catch (e) {\n  if (/Self Reference/.test(e.message)) { console.warn('Refused self/ancestor reparent of cell ' + cell.id); }\n  else throw e;\n}","preventionTips":["Always guard model.add with parent !== cell and mxGraphModel.isAncestor checks.","In group/drag handlers, exclude the new parent from cells being reparented.","Keep parent/child variables clearly named to avoid swaps."],"tags":["mxgraph","cycle","self-reference","graph-model"],"backgroundTag":"invalid-state-transition","analyzedSha":"c799cca99c7d064673dc79e6ef06a08bbc0e292d","analyzedAt":"2026-09-08T13:47:08.225Z","contentChangedAt":"2026-09-08T13:47:08.225Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}