{"record":{"id":"d00d598e526a8fb1","repo":"unslothai/unsloth","slug":"str-exc","errorCode":null,"errorMessage":"{str(exc)}","messagePattern":"\\{str\\(exc\\)\\}","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"studio/backend/hub/services/datasets/local.py","lineNumber":322,"sourceCode":"    ensure_dir(DATASET_UPLOAD_DIR)\n    stem = Path(filename).stem\n    stored_name = f\"{uuid.uuid4().hex}_{stem}{ext}\"\n    return filename, DATASET_UPLOAD_DIR / stored_name, max_bytes, max_label\n\n\ndef _native_upload_dataset_response(native_path_lease: str) -> UploadDatasetResponse:\n    from utils.native_path_leases import NativePathLeaseError, verify_native_path_lease\n\n    try:\n        grant = verify_native_path_lease(\n            native_path_lease,\n            operation = \"dataset-import\",\n            expected_kind = \"dataset\",\n            expected_path_type = \"file\",\n            allowed_suffixes = sorted(LOCAL_UPLOAD_EXTS),\n        )\n    except NativePathLeaseError as exc:\n        raise HTTPException(status_code = 400, detail = str(exc)) from exc\n\n    filename, stored_path, max_bytes, max_label = _upload_destination(grant.canonical_path.name)\n    if grant.size_bytes is not None and grant.size_bytes > max_bytes:\n        raise _upload_too_large(max_label)\n\n    written = 0\n    upload_complete = False\n    try:\n        with open(grant.canonical_path, \"rb\") as source, open(stored_path, \"wb\") as target:\n            while chunk := source.read(LOCAL_UPLOAD_CHUNK_BYTES):\n                written += len(chunk)\n                if written > max_bytes:\n                    raise _upload_too_large(max_label)\n                target.write(chunk)\n        upload_complete = True\n    except OSError as exc:\n        raise HTTPException(\n            status_code = 400,","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/hub/services/datasets/local.py#L304-L340","documentation":"HTTP 400 raised when `verify_native_path_lease` rejects the submitted native path lease for a dataset import. The lease is a signed/scoped grant (operation=dataset-import, kind=dataset, path_type=file, suffixes limited to LOCAL_UPLOAD_EXTS) and its error string is surfaced verbatim, so the detail text pinpoints which constraint failed: expired, tampered, wrong operation, wrong kind, wrong path type, or disallowed suffix.","triggerScenarios":"Reusing an old lease after expiry; presenting a lease minted for a different operation or a directory instead of a file; lease path pointing at a file with a non-allowed extension; lease signed for a different path than the one re-submitted.","commonSituations":"User sat on the import dialog past the lease TTL; app state restored from an old session replaying a stale lease; the native file was renamed or re-saved as another format between lease grant and import.","solutions":["Read the verbatim NativePathLeaseError message — it names the exact failed check (expiry, operation, kind, suffix, path).","Re-select the file in the native picker to mint a fresh lease and submit immediately.","Make sure the file still exists with the same name and an allowed extension at import time.","Do not cache or persist leases across sessions; they are single-purpose and short-lived by design."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Mint the lease and use it in the same user gesture; never persist it\nlease = pick_native_file(allowed_suffixes=[\".parquet\", \".json\", \".jsonl\", \".csv\"],\n                         operation=\"dataset-import\")\nif lease is None or lease_expired(lease):\n    re_prompt_user()","typeGuard":"def is_fresh_lease(lease: str) -> TypeGuard[str]:\n    try:\n        return verify_native_path_lease(lease, operation=\"dataset-import\",\n                                        expected_kind=\"dataset\",\n                                        expected_path_type=\"file\") is not None\n    except NativePathLeaseError:\n        return False","tryCatchPattern":"try:\n    upload_dataset(client, native_path_lease=lease)\nexcept HTTPStatusError as e:\n    if e.response.status_code == 400:\n        lease = re_mint_lease()  # detail text says which check failed; fresh lease fixes TTL issues\n        retry_once_with(lease)\n    else:\n        raise","preventionTips":["Never store leases in localStorage/session — mint fresh per import.","Re-select the file if the user waited on the dialog; leases are short-lived by design.","Keep the file's name and extension unchanged between lease grant and upload."],"tags":["upload","native-import","lease","validation","http-400"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}