{"record":{"id":"a4aee8149f6230a1","repo":"redis/redis-py","slug":"cannot-identify-slot-number-for-command-args-0","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/asyncio/cluster.py","lineNumber":3190,"sourceCode":"        slot_number: Optional[int] = None\n        if args[0] not in self.NO_SLOTS_COMMANDS:\n            slot_number = await 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 super().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    async def _immediate_execute_command(self, *args, **options):","sourceCodeStart":3172,"sourceCodeEnd":3208,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/asyncio/cluster.py#L3172-L3208","documentation":"RedisClusterException in the immediate/watching path (redis/asyncio/cluster.py:3190) when a command resolves to no slot (slot_number is None) and is not in NO_SLOTS_COMMANDS. In a WATCH/immediate context every command must be routable to a node; commands without keys (or with keys the library cannot extract) cannot be sent transactionally. This guards against ambiguous routing during a watched transaction.","triggerScenarios":"Issuing a keyless command like CONFIG GET, CLIENT INFO, or INFO inside a watched pipeline before MULTI; using a command whose key extraction the cluster router does not understand.","commonSituations":"Mixing admin/diagnostic commands into a watched transaction; custom or module commands whose first key position is not in the command table.","solutions":["Run keyless/admin commands outside the watched pipeline on the client directly","Ensure any command used in the transaction carries at least one key the router can extract","Register custom command key specifications if using module commands"],"exampleFix":"// before\nawait pipe.watch('k1')\npipe.execute_command('CONFIG', 'GET', 'maxmemory')\n// after - run admin command outside the transaction\nawait client.config_get('maxmemory')","handlingStrategy":"validation","validationCode":"from redis.cluster import _determine_slot_async_safe_check  # pseudonym\n# ensure command has at least one key before issuing inside a watched pipeline\nif command_has_no_key(cmd):\n    raise ValueError(f'{cmd} has no key; cannot run in watched transaction')","typeGuard":null,"tryCatchPattern":"try:\n    await pipe.execute_command(*cmd)\nexcept RedisClusterException as e:\n    if 'Cannot identify slot number' in str(e):\n        await client.execute_command(*cmd)  # run outside transaction","preventionTips":["Keep keyless/admin commands off the watched pipeline","Verify each transaction command carries a key the router can extract"],"tags":["cluster","pipeline","transaction","watch","slot-routing"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}