{"record":{"id":"985a39461c0cf9ec","repo":"redis/redis-py","slug":"no-targets-were-found-to-execute-c-args-command","errorCode":null,"errorMessage":"No targets were found to execute {c.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":4313,"sourceCode":"                                        response_policy=ResponsePolicy.DEFAULT_KEYED,\n                                    )\n                        else:\n                            if command_flag in self._pipe._command_flags_mapping:\n                                command_policies = CommandPolicies(\n                                    request_policy=self._pipe._command_flags_mapping[\n                                        command_flag\n                                    ]\n                                )\n                            else:\n                                command_policies = CommandPolicies()\n\n                    target_nodes = self._determine_nodes(\n                        *c.args,\n                        request_policy=command_policies.request_policy,\n                        node_flag=passed_targets,\n                    )\n                    if not target_nodes:\n                        raise RedisClusterException(\n                            f\"No targets were found to execute {c.args} command on\"\n                        )\n                c.command_policies = command_policies\n                if len(target_nodes) > 1:\n                    raise RedisClusterException(\n                        f\"Too many targets for command {c.args}\"\n                    )\n\n                node = target_nodes[0]\n                if node == self._pipe.get_default_node():\n                    is_default_node = True\n\n                # now that we know the name of the node\n                # ( it's just a string in the form of host:port )\n                # we can build a list of commands for each node.\n                node_name = node.name\n                if node_name not in nodes:\n                    redis_node = self._pipe.get_redis_connection(node)","sourceCodeStart":4295,"sourceCodeEnd":4331,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/cluster.py#L4295-L4331","documentation":"Raised in PipelineStrategy.send_cluster_commands (redis/cluster.py:4313) when _determine_nodes returns an empty list, meaning no cluster node matched the command's routing policy. The pipeline needs exactly one target node per stacked command, so an empty result means the command could not be placed on any node given the current slot map and request policy.","triggerScenarios":"Executing a pipeline command whose request policy resolves to zero nodes, e.g. a command flagged for REPLICAS when no replicas are known, or a keyed command whose slot maps to a node that has dropped out of the topology during execution. Also when a keyless command has no predefined flag and the DEFAULT_KEYLESS policy returns no nodes.","commonSituations":"Cluster with no replicas configured but code requests target_nodes='replicas'; topology refresh race where the cluster is mid-resharding/down; custom commands not registered in COMMAND INFO so the library cannot infer routing.","solutions":["Verify the cluster actually has nodes of the requested role (rc.cluster_nodes()) before targeting replicas/primaries explicitly.","Allow the library to auto-route by not passing target_nodes, or pass target_nodes='primaries' when replicas are absent.","Trigger a topology refresh (rc.cluster_forces_reread() / recreate the client) if the slot map is stale after a reshard.","Ensure the command is recognized by COMMAND INFO; for custom/module commands register the policy or pass an explicit target_node."],"exampleFix":"// before\nwith rc.pipeline() as pipe:\n    pipe.execute_command('GET', 'x', target_nodes='replicas')\n    pipe.execute()\n// after\nwith rc.pipeline() as pipe:\n    pipe.get('x')  # let cluster route to a primary or available replica\n    pipe.execute()","handlingStrategy":"validation","validationCode":"primaries = rc.get_primaries()\nif primaries:\n    with rc.pipeline() as pipe:\n        pipe.execute_command('GET', 'x', target_nodes='primaries')\n        pipe.execute()","typeGuard":"def has_nodes_of_role(rc, role: str) -> bool:\n    import redis.cluster as c\n    getter = {'primaries': rc.get_primaries, 'replicas': rc.get_replicas}[role]\n    return len(getter()) > 0","tryCatchPattern":"from redis.exceptions import RedisClusterException\ntry:\n    pipe.execute()\nexcept RedisClusterException as e:\n    if 'No targets were found' in str(e):\n        rc.cluster_forces_reread()  # refresh topology, then retry","preventionTips":["Check rc.get_primaries()/get_replicas() before explicit targeting.","Avoid explicit target_nodes in pipelines; let the library route."],"tags":["cluster","pipeline","routing","topology"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}