{"record":{"id":"0890b34d7962a318","repo":"reflex-dev/reflex","slug":"only-one-of-data-or-fp-may-be-provided-not-bo","errorCode":null,"errorMessage":"Only one of `data` or `fp` may be provided, not both.","messagePattern":"Only one of `data` or `fp` may be provided, not both\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"reflex/istate/manager/token.py","lineNumber":100,"sourceCode":"\n    @classmethod\n    def deserialize(\n        cls, data: bytes | None = None, fp: BinaryIO | None = None\n    ) -> TOKEN_TYPE:\n        \"\"\"Deserialize the state from redis/disk.\n\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.","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/reflex/istate/manager/token.py#L82-L118","documentation":"BaseStateToken.deserialize accepts either raw bytes (data) or a file-like object (fp), but not both at once — passing both is ambiguous about which source to load, so ValueError is raised. This is a guard on a classmethod API used internally by load_state and get_state to unpickle persisted state.","triggerScenarios":"Calling BaseStateToken.deserialize(data=pickled_bytes, fp=some_file) with both arguments non-None. Happens in custom state persistence/middleware code that reads a file into bytes but also keeps passing the open file handle.","commonSituations":"Adapters that wrap deserialize in custom storage backends; refactoring from fp-based to bytes-based loading and leaving both arguments in the call; copy-pasted plumbing that defaults both parameters.","solutions":["Pass exactly one source: data=raw_bytes if you already have bytes, else fp=file_obj","If reading from a file, use fp=open(path,'rb') or read the bytes first and pass only data","Add a unit test asserting your wrapper forwards exactly one argument"],"exampleFix":"# before\nstate = BaseStateToken.deserialize(data=raw, fp=fh)\n\n# after\nstate = BaseStateToken.deserialize(data=raw)","handlingStrategy":"validation","validationCode":"assert (data is None) != (fp is None), \"pass exactly one of data / fp\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In wrappers, accept only one source parameter and forward it","Add unit tests asserting your adapter never forwards both arguments"],"tags":["reflex","api-misuse","argument-validation","pickle"],"backgroundTag":"mutually-exclusive-arguments","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}