{"record":{"id":"2563704ed998e3d8","repo":"redis/redis-py","slug":"subcommand-subcommand-name-not-found-in-command","errorCode":null,"errorMessage":"Subcommand {subcommand_name} not found in command {command_name}","messagePattern":"Subcommand (.+?) not found in command (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/_parsers/commands.py","lineNumber":245,"sourceCode":"                The name of the subcommand to check, if applicable. If not provided,\n                the check is performed only on the command.\n\n        Returns:\n            bool\n                True if the specified command or subcommand is considered keyless,\n                False otherwise.\n\n        Raises:\n            ValueError\n                If the specified subcommand is not found within the command or the\n                specified command does not exist in the available commands.\n        \"\"\"\n        if subcommand_name:\n            for subcommand in self.commands.get(command_name)[\"subcommands\"]:\n                if str_if_bytes(subcommand[0]) == subcommand_name:\n                    parsed_subcmd = self.parse_subcommand(subcommand)\n                    return parsed_subcmd[\"first_key_pos\"] <= 0\n            raise ValueError(\n                f\"Subcommand {subcommand_name} not found in command {command_name}\"\n            )\n        else:\n            command_details = self.commands.get(command_name, None)\n            if command_details is not None:\n                return command_details[\"first_key_pos\"] <= 0\n\n            raise ValueError(f\"Command {command_name} not found in commands\")\n\n    def get_command_policies(self) -> PolicyRecords:\n        \"\"\"\n        Retrieve and process the command policies for all commands and subcommands.\n\n        This method traverses through commands and subcommands, extracting policy details\n        from associated data structures and constructing a dictionary of commands with their\n        associated policies. It supports nested data structures and handles both main commands\n        and their subcommands.\n","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/_parsers/commands.py#L227-L263","documentation":"Raised by the sync CommandsParser._is_keyless_command() (redis/_parsers/commands.py:245) when a subcommand name is not present among the parent command's 'subcommands' list (from COMMAND output). It is raised as ValueError and is consumed internally by get_command_policies() to classify subcommands as keyless/keyed for cluster routing.","triggerScenarios":"get_command_policies() iterates subcommands and calls _is_keyless_command(command, subcommand_name); if the subcommand_name doesn't string-match any subcommand[0] entry (expected 'PUBSUB|NUMSUB' form), this ValueError fires. Happens with formatting mismatches or server-version variance in subcommand naming.","commonSituations":"Server version exposing different/renamed subcommands than the client expects; module subcommands with non-standard naming; partial or reordered COMMAND output; internal invariant break after concurrent reinitialization.","solutions":["Inspect the command's 'subcommands' entries (COMMAND INFO <cmd>) to see the exact subcommand identifier strings the server reports.","Align the Redis server version across cluster nodes so subcommand names are consistent.","Upgrade redis-py to a release that understands the subcommand naming your server uses.","If reached via a custom code path, pass the subcommand name in the server's expected 'parent|child' form."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Confirm a subcommand exists in the parent's subcommands list before classifying\ninfo = r.execute_command(\"COMMAND\", \"INFO\", \"PUBSUB\")[0]\nsub_names = {s[0] for s in (info[9] if len(info) > 9 else [])}\nif f\"PUBSUB|{sub}\".upper() not in {n.decode().upper() if isinstance(n, bytes) else n.upper() for n in sub_names}:\n    raise ValueError(\"subcommand not registered on server\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Align Redis versions across cluster nodes so subcommand naming is consistent.","Upgrade redis-py to a release aware of the subcommand naming your server exposes.","When subclassing/extending, pass subcommand identifiers in the server's 'parent|child' form."],"tags":["cluster","commands","policies","internal"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}