{"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":4637,"sourceCode":"        slot_number: Optional[int] = None\n        if args[0] not in ClusterPipeline.NO_SLOTS_COMMANDS:\n            slot_number = self._pipe.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 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":4619,"sourceCodeEnd":4655,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/cluster.py#L4619-L4655","documentation":"Raised in TransactionStrategy.execute_command (redis/cluster.py:4636) when a command sent while watching (or in the immediate-execution path) has no determinable slot number. determine_slot(*args) returned None and the command is not in NO_SLOTS_COMMANDS, so the transaction cannot pin it to a node. This commonly happens for commands with no key or commands whose key position the library cannot introspect.","triggerScenarios":"Issuing a keyless or un-introspectable command while watching: e.g. pipe.watch('k'); pipe.execute_command('PING') or a custom/module command whose key spec COMMAND INFO does not expose. The slot cannot be derived, so the transaction aborts.","commonSituations":"Mixing admin or custom commands into a WATCH block. Module commands whose COMMAND INFO key position is not loaded. Calling execute_command directly with an unknown verb inside a transaction.","solutions":["Keep the WATCH/transaction path limited to standard keyed commands whose slot can be derived.","Move the non-keyed command out of the transaction and run it on the client with target_nodes.","For custom/module commands, ensure COMMAND INFO is available to the cluster client so determine_slot can find the key, or wrap the key in a known slot via hash tag and use the high-level method."],"exampleFix":"# before\npipe = rc.pipeline(transaction=True)\npipe.watch('k')\npipe.execute_command('PING')   # no slot -> raises\npipe.execute()\n\n# after\npipe = rc.pipeline(transaction=True)\npipe.watch('k')\npipe.multi()\npipe.set('k', 'v')\npipe.execute()\nrc.ping()  # keyless command outside the transaction","handlingStrategy":"validation","validationCode":"KEYLESS = {'PING', 'INFO', 'CONFIG', 'CLIENT', 'FLUSHALL', 'FLUSHDB', 'DBSIZE'}\n\ndef safe_txn_command(pipe, cmd, *args):\n    if cmd.upper() in KEYLESS:\n        raise ValueError(f'{cmd} has no key/slot and cannot run inside a cluster transaction')\n    pipe.execute_command(cmd, *args)","typeGuard":null,"tryCatchPattern":"from redis.exceptions import RedisClusterException\n\ntry:\n    pipe.execute_command(cmd, *args)\nexcept RedisClusterException as e:\n    if 'Cannot identify slot number' in str(e):\n        rc.execute_command(cmd, *args, target_nodes=RedisCluster.PRIMARIES)\n    else:\n        raise","preventionTips":["Keep WATCH/transaction bodies to standard keyed commands only.","Run admin/keyless commands on the client with target_nodes, outside the transaction.","Make sure module/custom commands expose their key spec via COMMAND INFO."],"tags":["cluster","pipeline","transaction","hashslot","keyless-command"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}