{"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":3158,"sourceCode":"        slot_number: Optional[int] = None\n        if args[0] not in self.NO_SLOTS_COMMANDS:\n            slot_number = await self._pipe.cluster_client._determine_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":3140,"sourceCodeEnd":3176,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/asyncio/cluster.py#L3140-L3176","documentation":"Raised in _execute_command when the pipeline is in WATCH/immediate mode, the command is NOT in NO_SLOTS_COMMANDS, but _determine_slot() returned None. The library treats the command as key-bearing but could not compute a slot for it, so it cannot route it inside a transaction.","triggerScenarios":"Issuing a command that is absent from the NO_SLOTS_COMMANDS allowlist yet has no key the slot resolver can use (e.g. a custom/module command, or a command form whose key position the library doesn't know) while inside a WATCH or pre-MULTI immediate-execution path of a cluster pipeline.","commonSituations":"Using a module command (RediSearch, RedisJSON, etc.) or a newly added Redis command inside a cluster transaction before the library's COMMAND metadata knows its key specification; calling such a command after WATCH().","solutions":["Run the offending command outside the transactional pipeline (await client.execute_command(...)) so the normal cluster routing path handles it.","If it is a known command missing from NO_SLOTS_COMMANDS or the key spec, open an issue / add the command's key spec to the library so _determine_slot can resolve it.","Use a hash-tagged key as the first argument if the command accepts one, so a slot can be derived."],"exampleFix":"// before\nawait pipe.watch('k')\nawait pipe.execute_command('FT.SEARCH', 'idx', 'q')  # no slot -> raises [82]\n// after\nres = await client.ft('idx').search('q')  # outside the transaction","handlingStrategy":"validation","validationCode":"# Confirm the command can resolve a slot before issuing it in a watched pipeline\nslot = await client._determine_slot(*args)\nif slot is None and args[0] not in pipe.NO_SLOTS_COMMANDS:\n    raise ValueError(f'{args[0]} cannot be routed in a transaction')","typeGuard":null,"tryCatchPattern":"from redis.exceptions import RedisClusterException\ntry:\n    await pipe.execute_command(*args)\nexcept RedisClusterException as e:\n    if 'Cannot identify slot number' in str(e):\n        await client.execute_command(*args)  # outside the txn","preventionTips":["Run custom/module commands outside the transactional pipeline.","Check NO_SLOTS_COMMANDS and _determine_slot before issuing in a WATCH block."],"tags":["cluster","pipeline","transaction","slot-resolution","commands"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}