{"record":{"id":"bfd02d8af6cf514b","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"node-with-name-node-node-name-already-exists-i","errorCode":null,"errorMessage":"Node with name '{node.node_name}' already exists in the graph.\n             You can change it by setting the 'node_name' attribute.","messagePattern":"Node with name '(.+?)' already exists in the graph\\.\n             You can change it by setting the 'node_name' attribute\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"scrapegraphai/graphs/base_graph.py","lineNumber":388,"sourceCode":"            logger.info(state[\"generated_code\"])\n        elif \"merged_script\" in state:\n            logger.info(state[\"merged_script\"])\n\n        logger.info(\"✨ Try enhanced version of ScrapegraphAI at %s ✨\", CLICKABLE_URL)\n\n        return state, exec_info\n\n    def append_node(self, node):\n        \"\"\"\n        Adds a node to the graph.\n\n        Args:\n            node (BaseNode): The node instance to add to the graph.\n        \"\"\"\n\n        # if node name already exists in the graph, raise an exception\n        if node.node_name in {n.node_name for n in self.nodes}:\n            raise ValueError(\n                f\"\"\"Node with name '{node.node_name}' already exists in the graph.\n                             You can change it by setting the 'node_name' attribute.\"\"\"\n            )\n\n        last_node = self.nodes[-1]\n        self.raw_edges.append((last_node, node))\n        self.nodes.append(node)\n        self.edges = self._create_edges(set(self.raw_edges))\n","sourceCodeStart":370,"sourceCodeEnd":397,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/graphs/base_graph.py#L370-L397","documentation":"BaseGraph.append_node refuses to add a node whose node_name already exists among the graph's nodes, because routing (edges dict keyed by node_name) and conditional-node resolution rely on unique names. The message suggests overriding the node_name attribute.","triggerScenarios":"Calling graph.append_node(FetchNode(...)) twice, or appending two nodes of the same class with default names (both default to e.g. 'fetch'); appending a node whose node_name was manually set to an existing one.","commonSituations":"Building custom pipelines in a loop that instantiates the same node class repeatedly; copy-pasting node blocks without changing node_name; appending a second FetchNode for retry logic.","solutions":["Give the new node a unique name via its constructor: FetchNode(node_name='fetch_retry', ...).","Skip the append if the name already exists (check {n.node_name for n in graph.nodes} first) when the node is intentionally identical.","Reuse the existing node instance instead of appending a duplicate."],"exampleFix":"# before\ngraph.append_node(FetchNode(node_config=cfg))\ngraph.append_node(FetchNode(node_config=cfg))  # duplicate default name 'fetch'\n\n# after\ngraph.append_node(FetchNode(node_config=cfg))\ngraph.append_node(FetchNode(node_name='fetch_second', node_config=cfg))","handlingStrategy":"validation","validationCode":"existing = {n.node_name for n in graph.nodes}\nif node.node_name in existing:\n    node.node_name = f'{node.node_name}_{len(existing)}'  # or skip\ngraph.append_node(node)","typeGuard":"def name_is_unique(node, graph) -> bool:\n    return node.node_name not in {n.node_name for n in graph.nodes}","tryCatchPattern":"try:\n    graph.append_node(node)\nexcept ValueError as e:\n    if 'already exists' in str(e):\n        node.node_name += '_2'\n        graph.append_node(node)\n    else:\n        raise","preventionTips":["Pass explicit node_name when appending same-class nodes.","Check the node-name set before appending in loops.","Prefer reusing existing instances over appending duplicates."],"tags":["graph-topology","duplicate-node","append","node-name"],"backgroundTag":"duplicate-node-name","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}