redis/redis-py · error · DataError

Only one of ```idmpauto``` or ```idmp``` may be specified

Error message

Only one of ```idmpauto``` or ```idmp``` may be specified

What it means

Raised by xadd() when both idmpauto and idmp are provided. idmpauto lets Redis compute an idempotent ID from entry content, while idmp supplies an explicit (producer_id, idempotent_id) pair; only one idempotency mode is allowed per XADD. It is a DataError.

Solutions

  1. Use idmpauto for automatic content-derived idempotency, OR idmp=(producer_id, idempotent_id) for explicit control — not both.
  2. Pick idmpauto when you want Redis to dedupe by content hash; pick idmp when you supply your own dedup key.

Example fix

# before
client.xadd('s', {'f': 'v'}, idmpauto='p1', idmp=('p1', b'iid'))

# after
client.xadd('s', {'f': 'v'}, idmpauto='p1')
Defensive patterns

Strategy: validation

Validate before calling

if idmpauto is not None and idmp is not None:
    raise ValueError('Specify only one of idmpauto or idmp')
client.xadd(name, fields, idmpauto=idmpauto, idmp=idmp)

Try / catch

from redis.exceptions import DataError
try:
    client.xadd(name, fields, idmpauto=idmpauto, idmp=idmp)
except DataError as e:
    if 'idmpauto' in str(e):
        idmp = None
        client.xadd(name, fields, idmpauto=idmpauto)

Prevention

When it happens

Trigger: Calling client.xadd('mystream', fields, idmpauto='producer-1', idmp=('producer-1', b'iid')).

Common situations: Experimenting with both idempotency modes, or passing both because of an unclear config schema.

Related errors


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

Appendix: source

Thrown at redis/commands/core.py:7019

            Automatically calculates an idempotent ID based on entry content to prevent
            duplicate entries. Can only be used with id='*'. Creates an IDMP map if it
            doesn't exist yet. The producer ID must be unique per producer and consistent
            across restarts.
        idmp: Tuple of (producer_id, idempotent_id) for explicit idempotent ID.
            Uses a specific idempotent ID to prevent duplicate entries. Can only be used
            with id='*'. The producer ID must be unique per producer and consistent across
            restarts. The idempotent ID must be unique per message and per producer.
            Shorter idempotent IDs require less memory and allow faster processing.
            Creates an IDMP map if it doesn't exist yet.

        For more information, see https://redis.io/commands/xadd
        """
        pieces: list[EncodableT] = []
        if maxlen is not None and minid is not None:
            raise DataError("Only one of ```maxlen``` or ```minid``` may be specified")

        if idmpauto is not None and idmp is not None:
            raise DataError("Only one of ```idmpauto``` or ```idmp``` may be specified")

        if (idmpauto is not None or idmp is not None) and id != "*":
            raise DataError("IDMPAUTO and IDMP can only be used with id='*'")

        if ref_policy is not None and ref_policy not in {"KEEPREF", "DELREF", "ACKED"}:
            raise DataError("XADD ref_policy must be one of: KEEPREF, DELREF, ACKED")

        if nomkstream:
            pieces.append(b"NOMKSTREAM")
        if ref_policy is not None:
            pieces.append(ref_policy)
        if idmpauto is not None:
            pieces.extend([b"IDMPAUTO", idmpauto])
        if idmp is not None:
            if not isinstance(idmp, tuple) or len(idmp) != 2:
                raise DataError(
                    "XADD idmp must be a tuple of (producer_id, idempotent_id)"
                )

View on GitHub (pinned to 6a6b581b48)