{"id":"a4606f91a9f0e089","repo":"redis/redis-py","slug":"xcfgset-idmp-duration-must-be-an-integer-between-1","errorCode":null,"errorMessage":"XCFGSET idmp_duration must be an integer between 1 and 300","messagePattern":"XCFGSET idmp_duration must be an integer between 1 and 300","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/commands/core.py","lineNumber":7122,"sourceCode":"        Returns:\n            OK on success.\n\n        For more information, see https://redis.io/commands/xcfgset\n        \"\"\"\n        if idmp_duration is None and idmp_maxsize is None:\n            raise DataError(\n                \"XCFGSET requires at least one of idmp_duration or idmp_maxsize\"\n            )\n\n        pieces: list[EncodableT] = []\n\n        if idmp_duration is not None:\n            if (\n                not isinstance(idmp_duration, int)\n                or idmp_duration < 1\n                or idmp_duration > 300\n            ):\n                raise DataError(\n                    \"XCFGSET idmp_duration must be an integer between 1 and 300\"\n                )\n            pieces.extend([b\"IDMP-DURATION\", idmp_duration])\n\n        if idmp_maxsize is not None:\n            if (\n                not isinstance(idmp_maxsize, int)\n                or idmp_maxsize < 1\n                or idmp_maxsize > 1000000\n            ):\n                raise DataError(\n                    \"XCFGSET idmp_maxsize must be an integer between 1 and 1,000,000\"\n                )\n            pieces.extend([b\"IDMP-MAXSIZE\", idmp_maxsize])\n\n        return self.execute_command(\"XCFGSET\", name, *pieces)\n\n    @overload","sourceCodeStart":7104,"sourceCodeEnd":7140,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/commands/core.py#L7104-L7140","documentation":"Raised by xcfgset() when idmp_duration is provided but is not an int, or is outside [1, 300]. This is the Redis stream-idmp-duration bound; the library enforces it client-side via a strict isinstance(int) check (so floats/strings fail; bool sneaks through because bool subclasses int).","triggerScenarios":"xcfgset(name, idmp_duration=0), =301, =3.5 (float), ='100' (str), =-5. Check at core.py:7117-7124: `not isinstance(idmp_duration, int) or <1 or >300`.","commonSituations":"Reading duration from YAML/env as a string; computing a float seconds value; off-by-one on the 300s ceiling; using -1 / 0 as a 'disable' sentinel (the minimum is 1, not 0).","solutions":["Pass an int between 1 and 300 inclusive.","If the value comes from config, coerce and clamp: v = max(1, min(300, int(raw))).","If you need to disable idempotency tracking, do not pass IDMP-DURATION at all (set only maxsize, or drop XCFGSET)."],"exampleFix":"# before\nr.xcfgset('s', idmp_duration=config['idle_secs'])  # '30' str -> fails\n# after\nr.xcfgset('s', idmp_duration=max(1, min(300, int(config['idle_secs']))))","handlingStrategy":"validation","validationCode":"def xcfg_duration(raw):\n    v = int(raw)\n    if not 1 <= v <= 300:\n        raise ValueError(f'idmp_duration out of range: {v}')\n    return v\nr.xcfgset(name, idmp_duration=xcfg_duration(raw))","typeGuard":null,"tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    r.xcfgset(name, idmp_duration=v)\nexcept DataError:\n    v = max(1, min(300, int(v))); r.xcfgset(name, idmp_duration=v)","preventionTips":["Coerce env/YAML values with int() before passing.","Remember the floor is 1, not 0."],"tags":["redis","streams","xcfgset","validation","range-error"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}