{"record":{"id":"e869cbc53cad57fe","repo":"reflex-dev/reflex","slug":"otp-field-high-level-wrapper-requires-a-static-int","errorCode":null,"errorMessage":"OTP field high-level wrapper requires a static integer `length`. Pass children explicitly for dynamic lengths.","messagePattern":"OTP field high-level wrapper requires a static integer `length`\\. Pass children explicitly for dynamic lengths\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/reflex-components-internal/src/reflex_components_internal/components/base/otp_field.py","lineNumber":187,"sourceCode":"        Raises:\n            ValueError: If `length` is missing when children are supplied, or\n                if `length` is not a positive integer when children are\n                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","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-internal/src/reflex_components_internal/components/base/otp_field.py#L169-L205","documentation":"The high-level rx.otp_field() wrapper must know how many input slots to render, so it requires a compile-time integer `length`. Passing a Var, string, bool, or omitting it leaves the wrapper unable to generate the N OTPFieldInput children. Reflex throws TypeError because the component tree is built at compile time in Python, not at runtime in the browser.","triggerScenarios":"Calling rx.otp_field() without `length`, passing length=\"6\" (string), length=State.var (a Var), or length=True (bool passes isinstance int check but is explicitly rejected).","commonSituations":"Trying to make OTP length dynamic from state (e.g. length=AppState.digits), or assuming a default exists because the low-level OTPFieldRoot/OTPFieldInput API is used elsewhere.","solutions":["Pass a static integer: rx.otp_field(length=6)","For dynamic lengths, compose the low-level parts explicitly: rx.otp_field.root(*[rx.otp_field.input() for _ in range(n)])","If length comes from state, fix it to a constant at compile time and hide/show slots instead"],"exampleFix":"# before\nrx.otp_field(length=State.otp_length)\n# after\nrx.otp_field(length=6)","handlingStrategy":"type-guard","validationCode":"length = 6\nassert isinstance(length, int) and not isinstance(length, bool), 'length must be a static int'","typeGuard":"def is_static_int(v) -> bool:\n    return isinstance(v, int) and not isinstance(v, bool)","tryCatchPattern":null,"preventionTips":["Always pass an explicit integer length to rx.otp_field","Never feed state Vars into length; keep slot count static"],"tags":["reflex","otp-field","component-create","static-analysis"],"backgroundTag":"component-prop-validation","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}