{"record":{"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":"exception","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/cluster.py","lineNumber":816,"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":798,"sourceCodeEnd":834,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/asyncio/cluster.py#L798-L834","documentation":"Raised by set_default_node when the supplied node is falsy or is not found in the cluster's node cache (get_node by node_name returns None). Prevents callers from pointing the cluster's default dispatch node at something the client did not discover.","triggerScenarios":"Calling client.set_default_node(stale_node) where stale_node came from a previous topology or a different cluster; passing None; passing a manually constructed ClusterNode whose name does not match any discovered node.","commonSituations":"Caching a node reference across a failover/resharding; building a ClusterNode by hand instead of via get_node/get_primaries; passing a node from one RedisCluster instance into another.","solutions":["Obtain the node from the same client via client.get_node(host=, port=) or client.get_primaries() before calling set_default_node.","Re-fetch the node after a topology change rather than reusing a stale reference.","If you only need a default for command routing, let the client pick its default_node automatically."],"exampleFix":"// before\nnode = client_other.get_primaries()[0]\nclient.set_default_node(node)\n// after\nnode = client.get_node(host='10.0.0.5', port=7000)\nif node is not None:\n    client.set_default_node(node)","handlingStrategy":"validation","validationCode":"node = client.get_node(host=node.host, port=node.port)\nif node is None:\n    raise ValueError(f'node {node} not in this cluster')\nclient.set_default_node(node)","typeGuard":"def node_belongs_to_cluster(client, node) -> bool:\n    return client.get_node(node_name=node.name) is not None","tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    client.set_default_node(node)\nexcept DataError as e:\n    if 'does not exist' in str(e):\n        node = client.get_primaries()[0]\n        client.set_default_node(node)\n    else:\n        raise","preventionTips":["Always obtain nodes via get_node/get_primaries on the same client.","Do not cache node references across topology changes."],"tags":["cluster","topology","node-routing","default-node"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}