{"id":"eef3c61ddcd66b57","repo":"redis/redis-py","slug":"wrong-command-or-module-name-command-name","errorCode":null,"errorMessage":"Wrong command or module name: {command_name}","messagePattern":"Wrong command or module name: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"redis/commands/policies.py","lineNumber":199,"sourceCode":"        pass\n\n\nclass BasePolicyResolver(PolicyResolver):\n    \"\"\"\n    Base class for policy resolvers.\n    \"\"\"\n\n    def __init__(\n        self, policies: PolicyRecords, fallback: Optional[PolicyResolver] = None\n    ) -> None:\n        self._policies = policies\n        self._fallback = fallback\n\n    def resolve(self, command_name: str) -> Optional[CommandPolicies]:\n        parts = command_name.split(\".\")\n\n        if len(parts) > 2:\n            raise ValueError(f\"Wrong command or module name: {command_name}\")\n\n        module, command = parts if len(parts) == 2 else (\"core\", parts[0])\n\n        if self._policies.get(module, None) is None:\n            if self._fallback is not None:\n                return self._fallback.resolve(command_name)\n            else:\n                return None\n\n        if self._policies.get(module).get(command, None) is None:\n            if self._fallback is not None:\n                return self._fallback.resolve(command_name)\n            else:\n                return None\n\n        return self._policies.get(module).get(command)\n\n    @abstractmethod","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/policies.py#L181-L217","documentation":"Raised by the sync BasePolicyResolver.resolve() when command_name, split on '.', yields more than two parts. The cluster policy resolver expects either 'COMMAND' (resolved to 'core.COMMAND') or 'module.COMMAND'. Three or more dots means a malformed command name. This is internal infrastructure used by RedisCluster for routing; application code rarely constructs these names directly.","triggerScenarios":"A custom command or module command is registered with a dotted name containing more than one dot, e.g. 'json.set.extra' or 'a.b.c'; the resolver is invoked via the cluster client's command path with such a name.","commonSituations":"Integrating a module whose name itself contains a dot; mis-joining module + command with an extra separator; incorrect STATIC_POLICIES registration for a new module command.","solutions":["Ensure command_name has at most one dot: 'module.COMMAND' or 'COMMAND'.","If a module name legitimately contains a dot, alias/escape it before resolution.","Update the policy table / CommandsParser to expose the command under a single-dot name."],"exampleFix":"// before\npolicies.resolve('json.set.extra')\n// after\npolicies.resolve('json.set')","handlingStrategy":"validation","validationCode":"def safe_resolve(resolver, command_name):\n    parts = command_name.split(\".\")\n    if len(parts) > 2:\n        raise ValueError(\n            f\"command_name must have at most one dot, got {command_name!r}\"\n        )\n    return resolver.resolve(command_name)","typeGuard":"def is_valid_command_name(name) -> bool:\n    return isinstance(name, str) and name.count(\".\") <= 1 and len(name) > 0","tryCatchPattern":"try:\n    resolver.resolve(command_name)\nexcept ValueError as e:\n    if \"Wrong command or module name\" in str(e):\n        command_name = command_name.rsplit(\".\", 1)[-1]  # last segment\n        resolver.resolve(command_name)\n    else:\n        raise","preventionTips":["Construct command names from a single (module, command) pair, never string-join arbitrary lists.","Keep module names free of dots in your STATIC_POLICIES table.","Add a unit test that every registered command name passes is_valid_command_name."],"tags":["cluster","policies","internal","valueerror"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}