redis/redis-py · error · RedisError

Cannot issue nested calls to MULTI

Error message

Cannot issue nested calls to MULTI

What it means

Raised by Pipeline.multi() when self.explicit_transaction is already True — i.e. MULTI has already been issued on this pipeline. Redis transactions cannot be nested; calling pipeline.multi() twice is a client-side programming error caught before anything is sent.

Solutions

  1. Call pipeline.multi() exactly once per transaction; remove the duplicate call.
  2. If constructing transactions conditionally, guard with a flag so multi() is invoked at most once.
  3. Reset the pipeline (pipe.reset() / new pipe) before starting a new transaction.

Example fix

// before
pipe = r.pipeline()
pipe.multi()
pipe.multi()  # RedisError

// after
pipe = r.pipeline()
pipe.multi()
pipe.set('k', 'v')
pipe.execute()
Defensive patterns

Strategy: validation

Validate before calling

if pipe.explicit_transaction:
    raise RuntimeError('MULTI already issued on this pipeline')
pipe.multi()

Type guard

def pipeline_can_enter_multi(pipe) -> bool:
    return not pipe.explicit_transaction

Try / catch

from redis.exceptions import RedisError
try:
    pipe.multi()
except RedisError as e:
    if 'nested calls to MULTI' in str(e):
        # already in a transaction; proceed to queue commands
        pass
    else:
        raise

Prevention

When it happens

Trigger: Calling pipe.multi() twice on the same Pipeline. The first call sets explicit_transaction=True; the second hits the guard at client.py:1888.

Common situations: Wrapping multi() in a helper that is called more than once; building transactions dynamically with a loop that re-enters multi(); copy-paste from an example that already calls multi().

Related errors


AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10). Data as JSON: /api/errors/4d6731ba93fe97c0. Report an issue: GitHub.

Appendix: source

Thrown at redis/client.py:1889

        self.explicit_transaction = False

        # we can safely return the connection to the pool here since we're
        # sure we're no longer WATCHing anything
        if self.connection:
            self.connection_pool.release(self.connection)
            self.connection = None

    def close(self) -> None:
        """Close the pipeline"""
        self.reset()

    def multi(self) -> None:
        """
        Start a transactional block of the pipeline after WATCH commands
        are issued. End the transactional block with `execute`.
        """
        if self.explicit_transaction:
            raise RedisError("Cannot issue nested calls to MULTI")
        if self.command_stack:
            raise RedisError(
                "Commands without an initial WATCH have already been issued"
            )
        self.explicit_transaction = True

    def execute_command(self, *args, **kwargs):
        if (self.watching or args[0] == "WATCH") and not self.explicit_transaction:
            return self.immediate_execute_command(*args, **kwargs)
        return self.pipeline_execute_command(*args, **kwargs)

    def _disconnect_reset_raise_on_watching(
        self,
        conn: AbstractConnection,
        error: Exception,
        failure_count: Optional[int] = None,
        start_time: Optional[float] = None,
        command_name: Optional[str] = None,

View on GitHub (pinned to 6a6b581b48)