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 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.
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.
Example fix
// before
node = client_other.get_primaries()[0]
client.set_default_node(node)
// after
node = client.get_node(host='10.0.0.5', port=7000)
if node is not None:
client.set_default_node(node) Defensive patterns
Strategy: validation
Validate before calling
node = client.get_node(host=node.host, port=node.port)
if node is None:
raise ValueError(f'node {node} not in this cluster')
client.set_default_node(node) Type guard
def node_belongs_to_cluster(client, node) -> bool:
return client.get_node(node_name=node.name) is not None Try / catch
from redis.exceptions import DataError
try:
client.set_default_node(node)
except DataError as e:
if 'does not exist' in str(e):
node = client.get_primaries()[0]
client.set_default_node(node)
else:
raise Prevention
- Always obtain nodes via get_node/get_primaries on the same client.
- Do not cache node references across topology changes.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to subscribe to cluster nodes
- No targets were found to execute
- No targets were found to execute
- No targets were found to execute
- Slot " " is not covered by the cluster.
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/a97001ed55bd8f23.
Report an issue: GitHub.
Appendix: source
Thrown at redis/asyncio/cluster.py:816
"""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 6a6b581b48)