{"record":{"id":"291124f02087d75b","repo":"redis/redis-py","slug":"method-is-not-supported-in-transactional-context","errorCode":null,"errorMessage":"Method is not supported in transactional context.","messagePattern":"Method is not supported in transactional context\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"redis/asyncio/cluster.py","lineNumber":3352,"sourceCode":"        for r, cmd in zip(responses, stack):\n            if isinstance(r, Exception):\n                self._annotate_exception(r, cmd.position + 1, cmd.args)\n\n                await record_operation_duration(\n                    command_name=\"TRANSACTION\",\n                    duration_seconds=time.monotonic() - start_time,\n                    server_address=self._transaction_connection.host,\n                    server_port=self._transaction_connection.port,\n                    db_namespace=str(self._transaction_connection.db),\n                    error=r,\n                )\n\n                raise r\n\n    def mset_nonatomic(\n        self, mapping: Mapping[AnyKeyT, EncodableT]\n    ) -> \"ClusterPipeline\":\n        raise NotImplementedError(\"Method is not supported in transactional context.\")\n\n    async def execute(\n        self, raise_on_error: bool = True, allow_redirections: bool = True\n    ) -> List[Any]:\n        stack = self._command_queue\n        if not stack and (not self._watching or not self._pipeline_slots):\n            return []\n\n        return await self._execute_transaction_with_retries(stack, raise_on_error)\n\n    async def _execute_transaction_with_retries(\n        self, stack: List[\"PipelineCommand\"], raise_on_error: bool\n    ):\n        return await self._retry.call_with_retry(\n            lambda: self._execute_transaction(stack, raise_on_error),\n            lambda error, failure_count: self._reinitialize_on_error(\n                error, failure_count\n            ),","sourceCodeStart":3334,"sourceCodeEnd":3370,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/asyncio/cluster.py#L3334-L3370","documentation":"NotImplementedError from TransactionStrategy.mset_nonatomic (redis/asyncio/cluster.py:3349). mset_nonatomic is inherently a non-atomic multi-key operation; it is meaningless inside an atomic (MULTI/EXEC) transaction, so the transactional strategy refuses it. The method only exists on the non-atomic strategy.","triggerScenarios":"Calling `pipe.mset_nonatomic({...})` on a ClusterPipeline whose execution strategy is TransactionStrategy (i.e. inside `multi()`/transaction=True flow).","commonSituations":"Switching a pipeline from non-transactional to transactional and forgetting to replace mset_nonatomic with regular mset.","solutions":["Use the regular mset/mapping inside a transaction (all keys must share a slot)","Drop the transaction and use the non-atomic pipeline strategy if you need mset_nonatomic","Loop individual SET commands inside the transaction"],"exampleFix":"// before\npipe.multi()\npipe.mset_nonatomic({'a':1, 'b':2})\n// after\npipe.multi()\npipe.mset({'a':1, 'b':2})  # keys must share a slot","handlingStrategy":"validation","validationCode":"if pipe._execution_strategy.__class__.__name__ == 'TransactionStrategy':\n    raise ValueError('mset_nonatomic is unsupported in a transaction; use mset')","typeGuard":null,"tryCatchPattern":"try:\n    pipe.mset_nonatomic(mapping)\nexcept NotImplementedError:\n    pipe.mset(mapping)  # inside transaction, same-slot keys only","preventionTips":["Use mset (not mset_nonatomic) inside transactions","Reserve mset_nonatomic for the non-atomic pipeline strategy"],"tags":["cluster","pipeline","transaction","mset"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}