{"id":"a97001ed55bd8f23","repo":"redis/redis-py","slug":"the-requested-node-does-not-exist-in-the-cluster","errorCode":null,"errorMessage":"The requested node does not exist in the cluster.","messagePattern":"The requested node does not exist in the cluster\\.","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/cluster.py","lineNumber":815,"sourceCode":"        \"\"\"Get the replica nodes of the cluster.\"\"\"\n        return self.nodes_manager.get_nodes_by_server_type(REPLICA)\n\n    def get_random_node(self) -> \"ClusterNode\":\n        \"\"\"Get a random node of the cluster.\"\"\"\n        return random.choice(list(self.nodes_manager.nodes_cache.values()))\n\n    def get_default_node(self) -> \"ClusterNode\":\n        \"\"\"Get the default node of the client.\"\"\"\n        return self.nodes_manager.default_node\n\n    def set_default_node(self, node: \"ClusterNode\") -> None:\n        \"\"\"\n        Set the default node of the client.\n\n        :raises DataError: if None is passed or node does not exist in cluster.\n        \"\"\"\n        if not node or not self.get_node(node_name=node.name):\n            raise DataError(\"The requested node does not exist in the cluster.\")\n\n        self.nodes_manager.default_node = node\n\n    def get_node(\n        self,\n        host: Optional[str] = None,\n        port: Optional[int] = None,\n        node_name: Optional[str] = None,\n    ) -> Optional[\"ClusterNode\"]:\n        \"\"\"Get node by (host, port) or node_name.\"\"\"\n        return self.nodes_manager.get_node(host, port, node_name)\n\n    def get_node_from_key(\n        self, key: str, replica: bool = False\n    ) -> Optional[\"ClusterNode\"]:\n        \"\"\"\n        Get the cluster node corresponding to the provided key.\n","sourceCodeStart":797,"sourceCodeEnd":833,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/asyncio/cluster.py#L797-L833","documentation":"Raised by RedisCluster.set_default_node (redis/asyncio/cluster.py:815) when the passed node is falsy or not present in the cluster's node cache (get_node returns None). The default node is used for cluster-wide commands; assigning an unknown node would route subsequent control commands to a non-member. Raises DataError.","triggerScenarios":"Calling set_default_node(some_node) where some_node was not discovered by the cluster, or set_default_node(None). The guard is `if not node or not self.get_node(node_name=node.name):`.","commonSituations":"Storing a ClusterNode captured before a topology refresh (failover/resharding) and re-applying it after the node left the cluster; passing a hand-constructed ClusterNode that was never discovered; passing None to 'reset'.","solutions":["Look up the node from the current cluster first: `n = c.get_node(host=x, port=y)` then `c.set_default_node(n)`.","Re-derive the node via get_primaries()/get_node_from_key() after a topology change.","Do not pass None; to reset, select an existing primary as the default."],"exampleFix":"// before\nc.set_default_node(old_node_saved_earlier)  # may have left cluster\n// after\nnode = c.get_node(host=host, port=port)\nif node is not None:\n    c.set_default_node(node)","handlingStrategy":"validation","validationCode":"node = c.get_node(host=host, port=port)\nif node is None:\n    raise ValueError(f'node {host}:{port} not in current cluster topology')\nc.set_default_node(node)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always look up nodes via get_node()/get_primaries() rather than caching them across topology changes.","Never pass None or a stale ClusterNode to set_default_node.","Refresh topology (trigger a MOVED or CLUSTER SLOTS) before re-applying a saved node."],"tags":["redis","asyncio","cluster","topology","default-node","routing"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}