{"record":{"id":"61de02f39a8129ea","repo":"redis/redis-py","slug":"xackdel-ref-policy-must-be-one-of-keepref-delref","errorCode":null,"errorMessage":"XACKDEL ref_policy must be one of: KEEPREF, DELREF, ACKED","messagePattern":"XACKDEL ref_policy must be one of: KEEPREF, DELREF, ACKED","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":6932,"sourceCode":"    ) -> Awaitable[int]: ...\n\n    def xackdel(\n        self,\n        name: KeyT,\n        groupname: GroupT,\n        *ids: StreamIdT,\n        ref_policy: Literal[\"KEEPREF\", \"DELREF\", \"ACKED\"] = \"KEEPREF\",\n    ) -> int | Awaitable[int]:\n        \"\"\"\n        Combines the functionality of XACK and XDEL. Acknowledges the specified\n        message IDs in the given consumer group and simultaneously attempts to\n        delete the corresponding entries from the stream.\n        \"\"\"\n        if not ids:\n            raise DataError(\"XACKDEL requires at least one message ID\")\n\n        if ref_policy not in {\"KEEPREF\", \"DELREF\", \"ACKED\"}:\n            raise DataError(\"XACKDEL ref_policy must be one of: KEEPREF, DELREF, ACKED\")\n\n        pieces = [name, groupname, ref_policy, \"IDS\", len(ids)]\n        pieces.extend(ids)\n        return self.execute_command(\"XACKDEL\", *pieces)\n\n    @overload\n    def xadd(\n        self: SyncClientProtocol,\n        name: KeyT,\n        fields: Dict[FieldT, EncodableT],\n        id: StreamIdT = \"*\",\n        maxlen: int | None = None,\n        approximate: bool = True,\n        nomkstream: bool = False,\n        minid: StreamIdT | None = None,\n        limit: int | None = None,\n        ref_policy: Literal[\"KEEPREF\", \"DELREF\", \"ACKED\"] | None = None,\n        idmpauto: str | None = None,","sourceCodeStart":6914,"sourceCodeEnd":6950,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/core.py#L6914-L6950","documentation":"Raised by xackdel() when ref_policy is not one of KEEPREF, DELREF, or ACKED. The reference policy controls how consumer-group pending entries are treated when acknowledging-and-deleting, and Redis only accepts those three literal tokens. It is a DataError.","triggerScenarios":"Calling client.xackdel('mystream', 'mygroup', '1234-0', ref_policy='keep') (wrong case), ref_policy='REMOVE', or any value outside the allowed set.","commonSituations":"Using lowercase or a typo for the policy name, or passing a user-provided string without validation.","solutions":["Use exactly one of 'KEEPREF', 'DELREF', or 'ACKED' (uppercase) for ref_policy.","If the value comes from user input, normalize to uppercase and validate against the allowed set before calling."],"exampleFix":"# before\nclient.xackdel('mystream', 'mygroup', '1234-0', ref_policy='keepref')\n\n# after\nclient.xackdel('mystream', 'mygroup', '1234-0', ref_policy='KEEPREF')","handlingStrategy":"validation","validationCode":"VALID_REF_POLICIES = {'KEEPREF', 'DELREF', 'ACKED'}\nif ref_policy not in VALID_REF_POLICIES:\n    raise ValueError(f'ref_policy must be one of {VALID_REF_POLICIES}')\nclient.xackdel(name, group, *ids, ref_policy=ref_policy)","typeGuard":"from typing import Literal\n\ndef is_valid_ref_policy(p: str) -> bool:\n    return p in {'KEEPREF', 'DELREF', 'ACKED'}\n\n# usage\nref_policy: Literal['KEEPREF', 'DELREF', 'ACKED'] = 'KEEPREF'","tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    client.xackdel(name, group, *ids, ref_policy=ref_policy)\nexcept DataError as e:\n    if 'ref_policy' in str(e):\n        client.xackdel(name, group, *ids, ref_policy='KEEPREF')","preventionTips":["Annotate ref_policy with Literal['KEEPREF','DELREF','ACKED'] so type checkers catch typos.","Normalize config/user input to uppercase and validate against the allowed set before calling."],"tags":["streams","xackdel","ref-policy","validation","enum"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}