{"record":{"id":"db7de79005f0e548","repo":"redis/redis-py","slug":"cannot-identify-slot-number-for-command-args-0-db7de7","errorCode":null,"errorMessage":"Cannot identify slot number for command: {args[0]},it cannot be triggered in a transaction","messagePattern":"Cannot identify slot number for command: (.+?),it cannot be triggered in a transaction","errorType":"exception","errorClass":"RedisClusterException","httpStatus":null,"severity":"error","filePath":"redis/cluster.py","lineNumber":4690,"sourceCode":"        slot_number: Optional[int] = None\n        if args[0] not in ClusterPipeline.NO_SLOTS_COMMANDS:\n            slot_number = self._resolve_transaction_slot(*args)\n\n        if (\n            self._watching or args[0] in self.IMMEDIATE_EXECUTE_COMMANDS\n        ) and not self._explicit_transaction:\n            if args[0] == \"WATCH\":\n                self._validate_watch()\n\n            if slot_number is not None:\n                if self._pipeline_slots and slot_number not in self._pipeline_slots:\n                    raise CrossSlotTransactionError(\n                        \"Cannot watch or send commands on different slots\"\n                    )\n\n                self._pipeline_slots.add(slot_number)\n            elif args[0] not in self.NO_SLOTS_COMMANDS:\n                raise RedisClusterException(\n                    f\"Cannot identify slot number for command: {args[0]},\"\n                    \"it cannot be triggered in a transaction\"\n                )\n\n            return self._immediate_execute_command(*args, **kwargs)\n        else:\n            if slot_number is not None:\n                self._pipeline_slots.add(slot_number)\n\n            return self.pipeline_execute_command(*args, **kwargs)\n\n    def _validate_watch(self):\n        if self._explicit_transaction:\n            raise RedisError(\"Cannot issue a WATCH after a MULTI\")\n\n        self._watching = True\n\n    def _immediate_execute_command(self, *args, **options):","sourceCodeStart":4672,"sourceCodeEnd":4708,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/cluster.py#L4672-L4708","documentation":"Raised by TransactionStrategy.execute_command (redis/cluster.py:4690) when a command in a WATCH/immediate-execution path cannot be assigned a slot number. determine_slot() returned None (the command has no key, or its keys could not be parsed) yet the command is not in NO_SLOTS_COMMANDS, so it cannot be placed in a transaction.","triggerScenarios":"Calling a command that has no keys (or whose keys COMMAND GETKEYS cannot resolve) inside a transactional pipeline's WATCH/immediate path, e.g. pipe.execute_command('INFO') or a custom module command without key metadata while watching.","commonSituations":"Custom/module commands not registered via COMMAND so the library cannot extract keys; zero-key commands mistaken for keyed ones; RESP2/RESP3 differences in COMMAND INFO output.","solutions":["Run keyless/admin commands outside the transactional pipeline (rc.info() directly).","Register or supply key info for custom commands so determine_slot can resolve a slot.","Ensure the transactional pipeline only contains genuinely keyed, single-slot commands."],"exampleFix":"// before\nwith rc.pipeline(transaction=True) as pipe:\n    pipe.watch('k')\n    pipe.execute_command('DBSIZE')\n// after\nwith rc.pipeline(transaction=True) as pipe:\n    pipe.watch('k')\n    pipe.get('k')\nrc.info()  # keyless command outside the transaction","handlingStrategy":"validation","validationCode":"NO_SLOTS = {'PING','INFO','DBSIZE','FLUSHALL','FLUSHDB','CONFIG'}\nwith rc.pipeline(transaction=True) as pipe:\n    pipe.watch('k')\n    for cmd in cmds:\n        if cmd[0].upper() in NO_SLOTS:\n            rc.execute_command(*cmd)  # outside transaction\n        else:\n            pipe.execute_command(*cmd)","typeGuard":"def is_keyless_command(name) -> bool:\n    return name.upper() in {'PING','INFO','DBSIZE','FLUSHALL','FLUSHDB','CONFIG','TIME'}","tryCatchPattern":"from redis.exceptions import RedisClusterException\ntry:\n    pipe.execute_command(*cmd)\nexcept RedisClusterException as e:\n    if 'Cannot identify slot' in str(e):\n        rc.execute_command(*cmd)  # run keyless command outside transaction","preventionTips":["Keep keyless/admin commands out of transactional pipelines.","Register custom commands so key extraction works."],"tags":["cluster","pipeline","transaction","routing","cross-slot"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}