{"record":{"id":"12663951e959bb20","repo":"redis/redis-py","slug":"command-command-name-not-found-in-commands","errorCode":null,"errorMessage":"Command {command_name} not found in commands","messagePattern":"Command (.+?) not found in commands","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/_parsers/commands.py","lineNumber":253,"sourceCode":"        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\n        Returns:\n            PolicyRecords: A collection of commands and subcommands associated with their\n            respective policies.\n\n        Raises:\n            IncorrectPolicyType: If an invalid policy type is encountered during policy extraction.\n        \"\"\"\n        command_with_policies = {}","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/_parsers/commands.py#L235-L271","documentation":"Raised by the sync CommandsParser._is_keyless_command() (redis/_parsers/commands.py:253) when command_name is absent from self.commands (the populated COMMAND cache). It is raised as ValueError and indicates the commands dict was queried for a command that was never cached or was removed.","triggerScenarios":"get_command_policies() calls _is_keyless_command(command) for each entry it is iterating, so under normal flow the key exists. This fires when self.commands was concurrently cleared/replaced, when a caller invokes _is_keyless_command with an arbitrary name, or when initialization is incomplete.","commonSituations":"Concurrent reinitialization resetting self.commands mid-policy-build; a code path passing a name not obtained from COMMAND; partial initialization due to a connection error during COMMAND.","solutions":["Ensure CommandsParser.initialize() fully completes before get_command_policies() is called.","Avoid concurrent reinit that could clear self.commands while policies are being computed.","Re-run initialize() against a healthy node and retry get_command_policies().","If it reproduces with a fully initialized cache, report it as a bug with the COMMAND output attached."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Ensure the COMMAND cache is initialized before computing policies\nfrom redis._parsers.commands import CommandsParser\np = CommandsParser(r)\nassert p.commands, \"commands cache is empty; initialize() did not complete\"\n# then call p.get_command_policies()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure CommandsParser.initialize() completes against a healthy node before get_command_policies().","Avoid concurrent reinitialization that could clear self.commands mid-build.","Re-run initialize() after node failover before recomputing policies."],"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"}