{"record":{"id":"083546a2fb1b292e","repo":"reflex-dev/reflex","slug":"otp-field-length-must-be-a-positive-integer","errorCode":null,"errorMessage":"OTP field `length` must be a positive integer.","messagePattern":"OTP field `length` must be a positive integer\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-components-internal/src/reflex_components_internal/components/base/otp_field.py","lineNumber":190,"sourceCode":"                auto-generated.\n            TypeError: If `length` is not an integer when children are\n                auto-generated (a Var can only be used with explicit children).\n        \"\"\"\n        if children:\n            if \"length\" not in props:\n                msg = \"OTP field `length` is required when passing children explicitly.\"\n                raise ValueError(msg)\n        else:\n            length = props.setdefault(\"length\", 6)\n            if not isinstance(length, int) or isinstance(length, bool):\n                msg = (\n                    \"OTP field high-level wrapper requires a static integer `length`.\"\n                    \" Pass children explicitly for dynamic lengths.\"\n                )\n                raise TypeError(msg)\n            if length <= 0:\n                msg = \"OTP field `length` must be a positive integer.\"\n                raise ValueError(msg)\n            children = tuple(OTPFieldInput.create() for _ in range(length))\n\n        return OTPFieldRoot.create(*children, **props)\n\n\nclass OTPField(ComponentNamespace):\n    \"\"\"Namespace for OTP field components.\"\"\"\n\n    root = staticmethod(OTPFieldRoot.create)\n    input = staticmethod(OTPFieldInput.create)\n    separator = staticmethod(OTPFieldSeparator.create)\n    class_names = ClassNames\n    __call__ = staticmethod(HighLevelOTPField.create)\n\n\notp_field = OTPField()\n","sourceCodeStart":172,"sourceCodeEnd":207,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-internal/src/reflex_components_internal/components/base/otp_field.py#L172-L207","documentation":"The OTP field wrapper validates that `length` is a positive integer before generating that many OTPFieldInput children. Zero or negative lengths would render an empty/invalid OTP group, so Reflex fails fast with ValueError.","triggerScenarios":"rx.otp_field(length=0), rx.otp_field(length=-1), or computing length from a constant that evaluates to <= 0.","commonSituations":"Using length=0 as a 'hide the field' trick, or deriving length from user config that can be zero.","solutions":["Pass a positive integer such as rx.otp_field(length=6)","Conditionally render the whole component instead of using length=0: rx.cond(State.show_otp, rx.otp_field(length=6))"],"exampleFix":"# before\nrx.otp_field(length=0)\n# after\nrx.cond(State.show_otp, rx.otp_field(length=6))","handlingStrategy":"validation","validationCode":"if length <= 0:\n    raise ValueError('OTP length must be >= 1')\nrx.otp_field(length=length)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate user-supplied config lengths before rendering","Use rx.cond to hide the field instead of length=0"],"tags":["reflex","otp-field","value-error","validation"],"backgroundTag":"component-prop-validation","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}