{"record":{"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/6a6b581b48225afa0b76912d1028c6035baee932/redis/commands/core.py#L7104-L7140","documentation":"Raised by Redis.xcfgset() when the idmp_duration argument is not a Python int, or falls outside the allowed range [1, 300]. idmp_duration is the idempotency window duration (seconds) tracked for stream commands; the client validates it before sending XCFGSET to the server. Passing None skips the check entirely.","triggerScenarios":"Calling r.xcfgset('mystream', idmp_duration=<v>) where <v> is a float (1.5), a numeric string ('10'), bool False (==0), or an int outside 1..300 such as 0, -1, or 301. The guard is `not isinstance(idmp_duration, int) or v < 1 or v > 300`.","commonSituations":"Loading the value from an env var or config file (arrives as str), using a float to express fractional seconds, or an off-by-one on the upper bound (300).","solutions":["Pass an int within [1, 300], e.g. idmp_duration=10.","If the value comes from config/env, coerce it first: idmp_duration=int(value) and clamp into range.","Do not pass fractional seconds; round to the nearest whole second within bounds."],"exampleFix":"# before\nr.xcfgset('mystream', idmp_duration=1.5)\n\n# after\nr.xcfgset('mystream', idmp_duration=2)\n# or, from config:\nr.xcfgset('mystream', idmp_duration=max(1, min(300, int(cfg['idmp_duration']))))","handlingStrategy":"validation","validationCode":"def valid_idmp_duration(v):\n    return v is None or (isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 300)\n\nif not valid_idmp_duration(idmp_duration):\n    raise ValueError('idmp_duration must be int in [1,300]')","typeGuard":"lambda v: v is None or (isinstance(v, int) and not isinstance(v, bool) and 1 <= v <= 300)","tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    r.xcfgset('mystream', idmp_duration=dur)\nexcept DataError as e:\n    # fix the config source, do not retry unchanged\n    log.warning('bad idmp_duration %r: %s', dur, e)","preventionTips":["Treat idmp_duration as a bounded integer at the config boundary, not at the call site.","Remember bool is a subclass of int in Python; reject it explicitly if it matters."],"tags":["stream","xcfgset","validation","idempotency"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}