{"id":"860ade2484c2cfc4","repo":"redis/redis-py","slug":"no-targets-were-found-to-execute-cmd-args-comman","errorCode":null,"errorMessage":"No targets were found to execute {cmd.args} command on","messagePattern":"No targets were found to execute (.+?) command on","errorType":"exception","errorClass":"RedisClusterException","httpStatus":null,"severity":"error","filePath":"redis/asyncio/cluster.py","lineNumber":2939,"sourceCode":"                                response_policy=ResponsePolicy.DEFAULT_KEYED,\n                            )\n                    else:\n                        if command_flag in client._command_flags_mapping:\n                            command_policies = CommandPolicies(\n                                request_policy=client._command_flags_mapping[\n                                    command_flag\n                                ]\n                            )\n                        else:\n                            command_policies = CommandPolicies()\n\n                target_nodes = await client._determine_nodes(\n                    *cmd.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 {cmd.args} command on\"\n                    )\n            cmd.command_policies = command_policies\n            if len(target_nodes) > 1:\n                raise RedisClusterException(f\"Too many targets for command {cmd.args}\")\n            node = target_nodes[0]\n            if node.name not in nodes:\n                nodes[node.name] = (node, [])\n            nodes[node.name][1].append(cmd)\n\n        # Start timing for observability\n        start_time = time.monotonic()\n\n        errors = await asyncio.gather(\n            *(\n                asyncio.create_task(node[0].execute_pipeline(node[1]))\n                for node in nodes.values()\n            )","sourceCodeStart":2921,"sourceCodeEnd":2957,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/asyncio/cluster.py#L2921-L2957","documentation":"The pipeline-execution analogue of error 65: raised inside the pipeline execute path when _determine_nodes() returns an empty list for a queued command. A pipeline command must resolve to at least one target node; zero means the routing policy found no candidate (e.g. replica policy with no replicas, or empty node group) and the pipeline cannot place the command.","triggerScenarios":"Queuing a replica-routed read in a pipeline when the cluster has no replicas; a pipeline command whose policy targets a node group that is empty in the current topology; transient empty node set during failover when the pipeline flushes.","commonSituations":"read_from_replicas=True with no replicas present; long-lived pipeline that buffers commands while topology changes underneath; pipeline issued right after client construction before topology settled.","solutions":["Pass target_nodes explicitly on the pipeline command so routing bypasses policy resolution.","If using read_from_replicas, ensure replicas exist (CLUSTER NODES) or set read_from_replicas=False.","Refresh topology (await rc.refresh_nodes()) and retry the pipeline after failover completes."],"exampleFix":"// before\npipe = rc.pipeline()\npipe.get('k')\nawait pipe.execute()  # read_from_replicas=True, no replicas\n\n// after\npipe = rc.pipeline()\npipe.get('k', target_nodes=RedisCluster.PRIMARIES)\nawait pipe.execute()","handlingStrategy":"fallback","validationCode":"async def pipelined_read(rc, key):\n    if rc.read_from_replicas and not rc.get_replicas():\n        pipe = rc.pipeline()\n        pipe.get(key, target_nodes=RedisCluster.PRIMARIES)\n        return (await pipe.execute())[0]\n    pipe = rc.pipeline()\n    pipe.get(key)\n    return (await pipe.execute())[0]","typeGuard":"from redis.asyncio.cluster import RedisCluster\n\ndef pipeline_has_targets(rc: RedisCluster) -> bool:\n    return bool(rc.get_primaries())","tryCatchPattern":"from redis.cluster import RedisClusterException\n\npipe = rc.pipeline()\npipe.get('k')\ntry:\n    await pipe.execute()\nexcept RedisClusterException as e:\n    if 'No targets' in str(e):\n        await rc.refresh_table_nodes()\n        pipe = rc.pipeline()\n        pipe.get('k', target_nodes=RedisCluster.PRIMARIES)\n        await pipe.execute()\n    else:\n        raise","preventionTips":["Pass target_nodes explicitly on pipeline commands when topology may be degraded.","Don't enable read_from_replicas without confirming replicas exist.","Refresh topology before flushing long-lived pipelines after a failover."],"tags":["redis-cluster","pipeline","routing","no-targets"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}