{"record":{"id":"d3ff38515127f427","repo":"redis/redis-py","slug":"no-targets-were-found-to-execute-args-command-on","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/asyncio/cluster.py","lineNumber":1186,"sourceCode":"            if self._initialize:\n                await self.initialize(last_failed_node_name=last_failed_node_name)\n                last_failed_node_name = None\n                if (\n                    len(target_nodes) == 1\n                    and target_nodes[0] == self.get_default_node()\n                ):\n                    # Replace the default cluster node\n                    self.replace_default_node()\n            try:\n                if not target_nodes_specified:\n                    # Determine the nodes to execute the command on\n                    target_nodes = await self._determine_nodes(\n                        *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 {args} command on\"\n                        )\n\n                if len(target_nodes) == 1:\n                    # Return the processed result\n                    ret = await self._execute_command(target_nodes[0], *args, **kwargs)\n                    if command in self.result_callbacks:\n                        ret = self.result_callbacks[command](\n                            command, {target_nodes[0].name: ret}, **kwargs\n                        )\n                    return self._policies_callback_mapping[\n                        command_policies.response_policy\n                    ](ret)\n                else:\n                    keys = [node.name for node in target_nodes]\n                    values = await asyncio.gather(\n                        *(\n                            asyncio.create_task(","sourceCodeStart":1168,"sourceCodeEnd":1204,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/asyncio/cluster.py#L1168-L1204","documentation":"Raised inside the main execute_command path when _determine_nodes() returns an empty list for a command. The policy callback resolved to zero candidate nodes, so there is nowhere to send the command and the client refuses rather than silently dropping it.","triggerScenarios":"A command whose policy resolves to a node group that is currently empty in the cache, e.g. requesting REPLICAS when no replicas are known, or ALL_NODES before initialize() completed; also possible right after all primaries were removed during a refresh.","commonSituations":"Cluster with no replicas deployed but read_from_replicas=True and a replica-routed command; running commands before await rc.initialize() finished; transient empty cache during failover.","solutions":["Ensure the cluster is initialised (await rc.initialize()) before issuing commands, or rely on the auto-init that execute_command triggers.","If targeting replicas, confirm replicas exist (rc.get_nodes(); server_type == 'replica') before using rc.REPLICAS.","Re-issue the command after topology refresh; if it persists, inspect rc.get_nodes() to see what the cache actually contains.","Fall back to an explicit target_nodes= argument pointing at a known-good primary."],"exampleFix":"// before\nawait rc.execute_command('GET', 'x', target_nodes=rc.REPLICAS)  # no replicas exist\n\n// after\nawait rc.initialize()\nnodes = rc.get_nodes()\nif any(n.server_type == 'replica' for n in nodes.values()):\n    await rc.execute_command('GET', 'x', target_nodes=rc.REPLICAS)\nelse:\n    await rc.execute_command('GET', 'x')","handlingStrategy":"validation","validationCode":"async def ensured_execute(rc, *args, **kwargs):\n    await rc.initialize()\n    if kwargs.get('target_nodes') == rc.REPLICAS and not rc.get_replicas():\n        kwargs['target_nodes'] = rc.PRIMARIES\n    return await rc.execute_command(*args, **kwargs)","typeGuard":"null","tryCatchPattern":"from redis.exceptions import RedisClusterException\nfor _ in range(3):\n    try:\n        return await rc.execute_command(*args, **kwargs)\n    except RedisClusterException as e:\n        if 'No targets were found' not in str(e):\n            raise\n        await rc.initialize()\nraise RuntimeError('no targets after refresh')","preventionTips":["Await rc.initialize() before issuing commands in freshly constructed clients.","Before targeting rc.REPLICAS, confirm replicas exist via rc.get_replicas().","Provide an explicit target_nodes= fallback for node-group-routed commands."],"tags":["cluster","routing","topology","empty-result"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}