{"record":{"id":"634c5ed898db3bd2","repo":"reflex-dev/reflex","slug":"malformed-upload-event-args","errorCode":null,"errorMessage":"Malformed upload event args.","messagePattern":"Malformed upload event args\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/reflex-components-core/src/reflex_components_core/core/_upload.py","lineNumber":551,"sourceCode":"\ndef _decode_event_args(encoded: str | None) -> dict[str, Any]:\n    \"\"\"Decode the extra bound handler args sent alongside an upload.\n\n    Args:\n        encoded: The JSON-encoded args form field value, or ``None`` if absent.\n\n    Returns:\n        The decoded extra args, or an empty mapping if none were sent.\n\n    Raises:\n        HTTPException: If the value is present but not a valid JSON object.\n    \"\"\"\n    if not encoded:\n        return {}\n    try:\n        decoded = json.loads(encoded)\n    except json.JSONDecodeError as exc:\n        raise HTTPException(\n            status_code=400, detail=\"Malformed upload event args.\"\n        ) from exc\n    if not isinstance(decoded, dict):\n        raise HTTPException(\n            status_code=400, detail=\"Upload event args must be a JSON object.\"\n        )\n    return decoded\n\n\ndef _buffered_upload_args(form_data: FormData) -> dict[str, Any]:\n    \"\"\"Decode the bound handler args from a buffered upload's form data.\n\n    Args:\n        form_data: The parsed multipart form data.\n\n    Returns:\n        The decoded extra args, or an empty mapping if none were sent.\n","sourceCodeStart":533,"sourceCodeEnd":569,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-core/src/reflex_components_core/core/_upload.py#L533-L569","documentation":"The upload-event-args text field must be a JSON document; json.loads failing raises HTTPException 400 'Malformed upload event args.' chained from the JSONDecodeError. Empty input is allowed and decodes to {}.","triggerScenarios":"The args form field contains invalid JSON (truncated payload, plain form text, encoding corruption) when the server decodes bound handler arguments.","commonSituations":"Custom clients sending URL-encoded or form-serialized values instead of JSON; truncated bodies from size limits; double-encoding (JSON string of a JSON string); tests posting arbitrary text in the args field.","solutions":["Send the args field as a strict JSON object string, e.g. '{\"arg1\": 1}'","Verify the client isn't form-encoding the value; use JSON.stringify exactly once","Inspect the chained JSONDecodeError for the exact syntax offset"],"exampleFix":"# before\ncurl -F 'args=arg1=1&arg2=2' ...\n\n# after\ncurl -F 'args={\"arg1\": 1, \"arg2\": 2}' ...","handlingStrategy":"validation","validationCode":"json.loads(args_str)  # raises locally if client-side payload is malformed","typeGuard":"def is_json_args(s: str) -> bool:\n    import json\n    try:\n        json.loads(s)\n        return True\n    except json.JSONDecodeError:\n        return False","tryCatchPattern":"except json.JSONDecodeError as e:\n    fix_payload(e.pos)  # validate before sending","preventionTips":["JSON.stringify the args exactly once","Log the raw args field when a 400 occurs to spot encoding issues"],"tags":["upload","json","http-400"],"backgroundTag":"invalid-json-payload","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}