{"record":{"id":"870237e8a6794650","repo":"redis/redis-py","slug":"no-targets-were-found-to-execute-args-command-on-870237","errorCode":null,"errorMessage":"No targets were found to execute {args} command on","messagePattern":"No targets were found to execute (.+?) command on","errorType":"exception","errorClass":"RedisClusterException","httpStatus":null,"severity":"error","filePath":"redis/cluster.py","lineNumber":1623,"sourceCode":"        execute_attempts = 1 + retry_attempts\n        failure_count = 0\n\n        # Start timing for observability\n        start_time = time.monotonic()\n\n        for _ in range(execute_attempts):\n            try:\n                res = {}\n                if not target_nodes_specified:\n                    # Determine the nodes to execute the command on\n                    target_nodes = self._determine_nodes(\n                        *args,\n                        request_policy=command_policies.request_policy,\n                        nodes_flag=passed_targets,\n                    )\n\n                    if not target_nodes:\n                        raise RedisClusterException(\n                            f\"No targets were found to execute {args} command on\"\n                        )\n                    if (\n                        len(target_nodes) == 1\n                        and target_nodes[0] == self.get_default_node()\n                    ):\n                        is_default_node = True\n                for node in target_nodes:\n                    res[node.name] = self._execute_command(node, *args, **kwargs)\n\n                    if command_policies.response_policy == ResponsePolicy.ONE_SUCCEEDED:\n                        break\n\n                # Return the processed result\n                return self._process_result(\n                    args[0],\n                    res,\n                    response_policy=command_policies.response_policy,","sourceCodeStart":1605,"sourceCodeEnd":1641,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/cluster.py#L1605-L1641","documentation":"Raised as a RedisClusterException by _internal_execute_command() when _determine_nodes() returns an empty list, meaning the routing logic found no nodes to send the command to. This happens when the command's request policy resolves to a node group that is empty in the current topology (e.g., command routed to REPLICAS but no replicas exist, or to a specific slot that has no serving node). The guard is at cluster.py:1622-1625.","triggerScenarios":"Running a command whose policy targets replicas (target_nodes='REPLICAS' or a command with a replica request policy) in a cluster with no replica nodes, or running a command when all candidate nodes have been removed from the node cache during topology refresh.","commonSituations":"A cluster configured with no replicas where read_from_replicas routes to the replica group, or a topology refresh that just ran and temporarily cleared node groups, or a command flag misconfiguration.","solutions":["Verify the cluster has nodes of the required type (e.g., run CLUSTER NODES to confirm replicas exist if routing to REPLICAS).","Pass an explicit target_nodes that is guaranteed non-empty, e.g. target_nodes='PRIMARIES' or a specific ClusterNode.","Retry after a topology refresh completes if the error is transient."],"exampleFix":"// before\nclient.execute_command('GET', 'key', target_nodes='REPLICAS')  # no replicas exist\n\n// after\nclient.execute_command('GET', 'key', target_nodes='PRIMARIES')","handlingStrategy":"try-catch","validationCode":"# Verify the target node group is non-empty before executing\nif not client.get_primaries():\n    raise RuntimeError('No primary nodes available in the cluster')","typeGuard":"def has_available_nodes(client, group='PRIMARIES') -> bool:\n    if group == 'PRIMARIES':\n        return len(client.get_primaries()) > 0\n    if group == 'REPLICAS':\n        return len(client.get_replicas()) > 0\n    return len(client.get_nodes()) > 0","tryCatchPattern":"from redis.exceptions import RedisClusterException\ntry:\n    result = client.execute_command('GET', 'key', target_nodes='REPLICAS')\nexcept RedisClusterException as e:\n    if 'No targets were found' in str(e):\n        result = client.execute_command('GET', 'key', target_nodes='PRIMARIES')","preventionTips":["Verify the target node group has members before routing to it (e.g., check replicas exist before routing to REPLICAS).","Fall back to PRIMARIES if REPLICAS is empty.","Handle transient empty-node-list errors during topology refresh with retry."],"tags":["cluster-routing","no-targets","replicas","topology"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}