{"record":{"id":"6727799f74e55fd9","repo":"reflex-dev/reflex","slug":"at-least-one-of-data-or-fp-must-be-provided","errorCode":null,"errorMessage":"At least one of `data` or `fp` must be provided.","messagePattern":"At least one of `data` or `fp` must be provided\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"reflex/istate/manager/token.py","lineNumber":106,"sourceCode":"\n        data and fp are mutually exclusive, but one must be provided.\n\n        Args:\n            data: The serialized state data.\n            fp: The file pointer to the serialized state data.\n\n        Returns:\n            The deserialized state instance.\n        \"\"\"\n        if data is not None and fp is not None:\n            msg = \"Only one of `data` or `fp` may be provided, not both.\"\n            raise ValueError(msg)\n        if data is not None:\n            return pickle.loads(data)\n        if fp is not None:\n            return pickle.load(fp)\n        msg = \"At least one of `data` or `fp` must be provided.\"\n        raise ValueError(msg)\n\n    @classmethod\n    def get_and_reset_touched_state(cls, state: TOKEN_TYPE) -> bool:\n        \"\"\"Get the touched state and reset the touched flag.\n\n        This is used to determine if a state has been modified since it was last serialized.\n\n        Args:\n            state: The state to check for modifications.\n\n        Returns:\n            The touched state of the state.\n        \"\"\"\n        # Default implementation is always to write the state.\n        return True\n\n\nclass BaseStateToken(StateToken[\"BaseState\"]):","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/reflex/istate/manager/token.py#L88-L124","documentation":"BaseStateToken.deserialize requires exactly one source of serialized state: either data (bytes) or fp (file object). If neither is provided there is nothing to unpickle, so it raises ValueError. It is the counterpart guard to the 'both provided' check and fires when the caller forwards empty/None payloads.","triggerScenarios":"Calling BaseStateToken.deserialize() with no arguments, or with data=None and fp=None — commonly when a caller reads a token store, gets no bytes back (missing/expired key), and passes the None through instead of short-circuiting.","commonSituations":"Custom storage backends returning None for missing keys; race where the Redis/disk token expired between existence check and read; refactors that drop the argument accidentally; code branching that forgets the third case (neither).","solutions":["Check for empty payload before calling deserialize and handle 'no state' by creating fresh state","If reading from storage, branch: data = store.get(key); if data is None: fresh_state() else deserialize(data=data)","Log the token/key when the payload is empty to identify expired or missing state"],"exampleFix":"# before\nstate = BaseStateToken.deserialize(data=data)  # data is None -> ValueError\n\n# after\nif data is None:\n    state = root_state_cls(_reflex_internal_init=True)\nelse:\n    state = BaseStateToken.deserialize(data=data)","handlingStrategy":"validation","validationCode":"if data is None and fp is None:\n    # no persisted state; create fresh instead of calling deserialize\n    state = root_state_cls(_reflex_internal_init=True)\nelse:\n    state = BaseStateToken.deserialize(data=data, fp=fp)","typeGuard":null,"tryCatchPattern":"try:\n    state = BaseStateToken.deserialize(data=data)\nexcept ValueError as e:\n    if \"At least one\" in str(e):\n        state = root_state_cls(_reflex_internal_init=True)\n    else:\n        raise","preventionTips":["Always check for empty payload from storage before deserializing","Treat missing tokens as 'create fresh state', not as an error path"],"tags":["reflex","api-misuse","argument-validation","missing-data"],"backgroundTag":"missing-required-argument","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}