redis/redis-py · error · DataError

The requested node does not exist in the cluster.

Error message

The requested node does not exist in the cluster.

What it means

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.

Source

Thrown at redis/asyncio/cluster.py:815

        """Get the replica nodes of the cluster."""
        return self.nodes_manager.get_nodes_by_server_type(REPLICA)

    def get_random_node(self) -> "ClusterNode":
        """Get a random node of the cluster."""
        return random.choice(list(self.nodes_manager.nodes_cache.values()))

    def get_default_node(self) -> "ClusterNode":
        """Get the default node of the client."""
        return self.nodes_manager.default_node

    def set_default_node(self, node: "ClusterNode") -> None:
        """
        Set the default node of the client.

        :raises DataError: if None is passed or node does not exist in cluster.
        """
        if not node or not self.get_node(node_name=node.name):
            raise DataError("The requested node does not exist in the cluster.")

        self.nodes_manager.default_node = node

    def get_node(
        self,
        host: Optional[str] = None,
        port: Optional[int] = None,
        node_name: Optional[str] = None,
    ) -> Optional["ClusterNode"]:
        """Get node by (host, port) or node_name."""
        return self.nodes_manager.get_node(host, port, node_name)

    def get_node_from_key(
        self, key: str, replica: bool = False
    ) -> Optional["ClusterNode"]:
        """
        Get the cluster node corresponding to the provided key.

View on GitHub (pinned to da03cdc7e8)

Solutions

  1. Look up the node from the current cluster first: `n = c.get_node(host=x, port=y)` then `c.set_default_node(n)`.
  2. Re-derive the node via get_primaries()/get_node_from_key() after a topology change.
  3. Do not pass None; to reset, select an existing primary as the default.

Example fix

// before
c.set_default_node(old_node_saved_earlier)  # may have left cluster
// after
node = c.get_node(host=host, port=port)
if node is not None:
    c.set_default_node(node)
Defensive patterns

Strategy: validation

Validate before calling

node = c.get_node(host=host, port=port)
if node is None:
    raise ValueError(f'node {host}:{port} not in current cluster topology')
c.set_default_node(node)

Prevention

When it happens

Trigger: 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):`.

Common situations: 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'.

Related errors


AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04). Data as JSON: /data/errors/a97001ed55bd8f23.json. Report an issue: GitHub.