{"id":"ccf0e7be2956a654","repo":"redis/redis-py","slug":"incorrect-request-policy-type-policy-type","errorCode":null,"errorMessage":"Incorrect request policy type: {policy_type}","messagePattern":"Incorrect request policy type: (.+?)","errorType":"exception","errorClass":"IncorrectPolicyType","httpStatus":null,"severity":"error","filePath":"redis/_parsers/commands.py","lineNumber":297,"sourceCode":"                command_name: The command name to associate with found policies\n            \"\"\"\n            if isinstance(data, (str, bytes)):\n                # Decode bytes to string if needed\n                policy = str_if_bytes(data.decode())\n\n                # Check if this is a policy string\n                if policy.startswith(\"request_policy\") or policy.startswith(\n                    \"response_policy\"\n                ):\n                    if policy.startswith(\"request_policy\"):\n                        policy_type = policy.split(\":\")[1]\n\n                        try:\n                            command_with_policies[module_name][\n                                command_name\n                            ].request_policy = RequestPolicy(policy_type)\n                        except ValueError:\n                            raise IncorrectPolicyType(\n                                f\"Incorrect request policy type: {policy_type}\"\n                            )\n\n                    if policy.startswith(\"response_policy\"):\n                        policy_type = policy.split(\":\")[1]\n\n                        try:\n                            command_with_policies[module_name][\n                                command_name\n                            ].response_policy = ResponsePolicy(policy_type)\n                        except ValueError:\n                            raise IncorrectPolicyType(\n                                f\"Incorrect response policy type: {policy_type}\"\n                            )\n\n            elif isinstance(data, list):\n                # For lists, recursively process each element\n                for item in data:","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/_parsers/commands.py#L279-L315","documentation":"Raised inside CommandsParser.get_command_policies() when the policy string parsed out of a command's 'tips' field has a request_policy:<value> whose <value> does not match any RequestPolicy enum member (e.g. 'request_policy:random'). The except ValueError re-raises as IncorrectPolicyType, a plain Exception subclass. This indicates an unknown routing hint in the server's COMMAND tips or a stale enum table in the client.","triggerScenarios":"Connecting to a Redis version or module that advertises a request_policy tip value the installed redis-py does not know; manually injecting custom tips; running a custom Redis fork that emits non-standard policy strings.","commonSituations":"Newer Redis / module version than redis-py supports; mixed-version cluster where one node advertises a policy string the client enum lacks; pre-release or experimental module.","solutions":["Upgrade redis-py to a version whose RequestPolicy enum includes the policy your server advertises.","Check the offending tip with 'redis-cli COMMAND INFO <cmd>' and look at the tips field.","If running a custom module, normalize its request_policy tip to one of the supported enum values.","Pin the module/Redis version to one known-compatible with your redis-py release."],"exampleFix":"// before\nrc = RedisCluster(...)\nrc.commands_parser.get_command_policies()  # IncorrectPolicyType\n\n// after\n# upgrade redis-py, or on the server side ensure tips only contain\n# supported values: all_nodes, all_shards, all_replicas, multi_shard,\n# special, default_keyless, default_keyed, default_node","handlingStrategy":"validation","validationCode":"# Sanity-check tip values against the enum before policy computation\nfrom redis._parsers.commands import RequestPolicy\nSUPPORTED = {p.value for p in RequestPolicy}\ndef tips_ok(cmd_info):\n    for tip in (cmd_info.get(\"tips\") or []):\n        if isinstance(tip, (bytes, str)) and b\"request_policy:\" in (tip.encode() if isinstance(tip, str) else tip):\n            val = (tip.decode() if isinstance(tip, bytes) else tip).split(\":\")[1]\n            if val not in SUPPORTED:\n                return False, val\n    return True, None","typeGuard":null,"tryCatchPattern":"try:\n    policies = rc.commands_parser.get_command_policies()\nexcept redis.exceptions.IncorrectPolicyType as e:\n    # unsupported request_policy value; upgrade client or patch module tips\n    raise","preventionTips":["Keep redis-py version aligned with your Redis/module version.","Inspect COMMAND INFO tips before relying on custom routing policies.","Patch custom modules to emit only supported request_policy strings.","Pin Redis/module to a version compatible with your redis-py."],"tags":["cluster","policies","commands","sync"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}