{"record":{"id":"2ea1b368971f80ae","repo":"redis/redis-py","slug":"target-nodes-type-can-be-one-of-the-following-nod-2ea1b3","errorCode":null,"errorMessage":"target_nodes type can be one of the following: node_flag (PRIMARIES, REPLICAS, RANDOM, ALL_NODES),ClusterNode, list<ClusterNode>, or dict<any, ClusterNode>. The passed type is {type(target_nodes)}","messagePattern":"target_nodes type can be one of the following: node_flag \\(PRIMARIES, REPLICAS, RANDOM, ALL_NODES\\),ClusterNode, list<ClusterNode>, or dict<any, ClusterNode>\\. The passed type is (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"redis/cluster.py","lineNumber":1527,"sourceCode":"        \"\"\"\n        return self.nodes_manager.connection_kwargs\n\n    def _is_nodes_flag(self, target_nodes):\n        return isinstance(target_nodes, str) and target_nodes in self.node_flags\n\n    def _parse_target_nodes(self, target_nodes):\n        if isinstance(target_nodes, list):\n            nodes = target_nodes\n        elif isinstance(target_nodes, ClusterNode):\n            # Supports passing a single ClusterNode as a variable\n            nodes = [target_nodes]\n        elif isinstance(target_nodes, dict):\n            # Supports dictionaries of the format {node_name: node}.\n            # It enables to execute commands with multi nodes as follows:\n            # rc.cluster_save_config(rc.get_primaries())\n            nodes = target_nodes.values()\n        else:\n            raise TypeError(\n                \"target_nodes type can be one of the following: \"\n                \"node_flag (PRIMARIES, REPLICAS, RANDOM, ALL_NODES),\"\n                \"ClusterNode, list<ClusterNode>, or dict<any, ClusterNode>. \"\n                f\"The passed type is {type(target_nodes)}\"\n            )\n        return nodes\n\n    def execute_command(self, *args, **kwargs):\n        return self._internal_execute_command(*args, **kwargs)\n\n    def _internal_execute_command(self, *args, **kwargs):\n        \"\"\"\n        Wrapper for ERRORS_ALLOW_RETRY error handling.\n\n        It will try the number of times specified by the retries property from\n        config option \"self.retry\" which defaults to 10 unless manually\n        configured.\n","sourceCodeStart":1509,"sourceCodeEnd":1545,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/cluster.py#L1509-L1545","documentation":"Raised as a TypeError by _parse_target_nodes() when the target_nodes argument is not one of the accepted types: a node_flag string (PRIMARIES, REPLICAS, RANDOM, ALL_NODES), a ClusterNode instance, a list of ClusterNode, or a dict mapping names to ClusterNode. The guard at cluster.py:1527-1532 checks isinstance for each valid type and raises for anything else, including the type in the message.","triggerScenarios":"Passing target_nodes as a string that isn't a node_flag, an integer, a tuple, or any object that isn't ClusterNode or a container of ClusterNode, e.g. client.get('key', target_nodes=123) or target_nodes=' primaries' (typo).","commonSituations":"Passing the host:port string instead of a ClusterNode object, passing a single host string, or a typo in the node_flag constant name.","solutions":["Use the node_flag string constants: 'PRIMARIES', 'REPLICAS', 'ALL_NODES', or 'RANDOM'.","Pass a ClusterNode obtained from client.get_node(host, port) or client.get_primaries().","Pass a list of ClusterNode objects or a dict of {name: ClusterNode}."],"exampleFix":"// before\nclient.execute_command('INFO', target_nodes='primary')\n\n// after\nclient.execute_command('INFO', target_nodes='PRIMARIES')","handlingStrategy":"type-guard","validationCode":"from redis.cluster import ClusterNode\nvalid_flags = {'PRIMARIES', 'REPLICAS', 'ALL_NODES', 'RANDOM'}\ndef validate_target_nodes(tn):\n    if isinstance(tn, str) and tn not in valid_flags:\n        raise TypeError(f'Invalid node_flag: {tn}. Use one of {valid_flags}')\n    if not isinstance(tn, (str, ClusterNode, list, dict)):\n        raise TypeError(f'Invalid target_nodes type: {type(tn)}')\n    return tn","typeGuard":"from redis.cluster import ClusterNode\nVALID_FLAGS = {'PRIMARIES', 'REPLICAS', 'ALL_NODES', 'RANDOM'}\ndef is_valid_target_nodes(tn) -> bool:\n    if isinstance(tn, str):\n        return tn in VALID_FLAGS\n    if isinstance(tn, ClusterNode):\n        return True\n    if isinstance(tn, list):\n        return all(isinstance(n, ClusterNode) for n in tn)\n    if isinstance(tn, dict):\n        return all(isinstance(v, ClusterNode) for v in tn.values())\n    return False","tryCatchPattern":"null","preventionTips":["Use the node_flag string constants exactly: PRIMARIES, REPLICAS, ALL_NODES, RANDOM.","Pass ClusterNode objects obtained from client.get_node() or get_primaries().","Never pass host:port strings or integers as target_nodes."],"tags":["target-nodes","type-error","cluster-routing","configuration"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}