{"id":"7a81acfda2ec1a9c","repo":"redis/redis-py","slug":"xadd-ref-policy-must-be-one-of-keepref-delref-a","errorCode":null,"errorMessage":"XADD ref_policy must be one of: KEEPREF, DELREF, ACKED","messagePattern":"XADD ref_policy must be one of: KEEPREF, DELREF, ACKED","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":7025,"sourceCode":"            with id='*'. The producer ID must be unique per producer and consistent across\n            restarts. The idempotent ID must be unique per message and per producer.\n            Shorter idempotent IDs require less memory and allow faster processing.\n            Creates an IDMP map if it doesn't exist yet.\n\n        For more information, see https://redis.io/commands/xadd\n        \"\"\"\n        pieces: list[EncodableT] = []\n        if maxlen is not None and minid is not None:\n            raise DataError(\"Only one of ```maxlen``` or ```minid``` may be specified\")\n\n        if idmpauto is not None and idmp is not None:\n            raise DataError(\"Only one of ```idmpauto``` or ```idmp``` may be specified\")\n\n        if (idmpauto is not None or idmp is not None) and id != \"*\":\n            raise DataError(\"IDMPAUTO and IDMP can only be used with id='*'\")\n\n        if ref_policy is not None and ref_policy not in {\"KEEPREF\", \"DELREF\", \"ACKED\"}:\n            raise DataError(\"XADD ref_policy must be one of: KEEPREF, DELREF, ACKED\")\n\n        if nomkstream:\n            pieces.append(b\"NOMKSTREAM\")\n        if ref_policy is not None:\n            pieces.append(ref_policy)\n        if idmpauto is not None:\n            pieces.extend([b\"IDMPAUTO\", idmpauto])\n        if idmp is not None:\n            if not isinstance(idmp, tuple) or len(idmp) != 2:\n                raise DataError(\n                    \"XADD idmp must be a tuple of (producer_id, idempotent_id)\"\n                )\n            pieces.extend([b\"IDMP\", idmp[0], idmp[1]])\n        if maxlen is not None:\n            if not isinstance(maxlen, int) or maxlen < 0:\n                raise DataError(\"XADD maxlen must be non-negative integer\")\n            pieces.append(b\"MAXLEN\")\n            if approximate:","sourceCodeStart":7007,"sourceCodeEnd":7043,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L7007-L7043","documentation":"Raised by xadd() when ref_policy is provided but is not one of KEEPREF, DELREF, or ACKED. The ref_policy governs how consumer-group PEL references are treated during XADD-driven trimming, and only those three literal values are accepted.","triggerScenarios":"Calling client.xadd(name, fields, maxlen=1000, ref_policy='keepref') (wrong case), ref_policy='random', or any value outside the allowed set while also trimming.","commonSituations":"Case mismatch; passing an invalid policy string from config; typo in the policy name.","solutions":["Use one of 'KEEPREF', 'DELREF', 'ACKED' exactly (uppercase), or omit ref_policy entirely.","Validate config-supplied policy values against the allowed set before calling xadd.","Remember ref_policy only takes effect alongside a trim (maxlen/minid)."],"exampleFix":"# before\nawait r.xadd('s', {'f':'v'}, maxlen=10, ref_policy='keepref')\n# after\nawait r.xadd('s', {'f':'v'}, maxlen=10, ref_policy='KEEPREF')","handlingStrategy":"type-guard","validationCode":"VALID_REF_POLICIES = {'KEEPREF', 'DELREF', 'ACKED'}\ndef validate_xadd_ref_policy(policy):\n    if policy is not None and policy not in VALID_REF_POLICIES:\n        raise ValueError(f'ref_policy must be one of {VALID_REF_POLICIES}')\n    return True","typeGuard":"def is_valid_ref_policy(p) -> bool:\n    return p is None or p in {'KEEPREF', 'DELREF', 'ACKED'}","tryCatchPattern":null,"preventionTips":["Use uppercase exact values or omit ref_policy entirely.","Remember ref_policy applies only when trimming (maxlen/minid).","Validate config strings against the allowed set before calling xadd."],"tags":["stream","xadd","ref-policy","validation","dataerror"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}