{"record":{"id":"0cdf2271d3e50c06","repo":"cocoindex-io/cocoindex","slug":"partial-reads-are-not-supported-for-google-drive-f","errorCode":null,"errorMessage":"Partial reads are not supported for Google Drive files.","messagePattern":"Partial reads are not supported for Google Drive files\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/connectors/google_drive/_source.py","lineNumber":124,"sourceCode":"                .get(\n                    fileId=self._file_id,\n                    fields=\"size, modifiedTime\",\n                )\n                .execute()\n            )\n            size_raw = response.get(\"size\")\n            size = int(size_raw) if size_raw is not None else 0\n            return file.FileMetadata(\n                size=size,\n                modified_time=_parse_modified_time(response.get(\"modifiedTime\")),\n            )\n\n        return await asyncio.to_thread(_fetch)\n\n    def _read_sync(self, size: int = -1) -> bytes:\n        \"\"\"Synchronously read file content (internal helper).\"\"\"\n        if size != -1:\n            raise ValueError(\"Partial reads are not supported for Google Drive files.\")\n\n        if self._mime_type in _EXPORT_MIME_BY_TYPE:\n            export_mime = _EXPORT_MIME_BY_TYPE[self._mime_type]\n            request = self._service.files().export_media(\n                fileId=self._file_id, mimeType=export_mime\n            )\n        else:\n            request = self._service.files().get_media(fileId=self._file_id)\n\n        fh = io.BytesIO()\n        downloader = MediaIoBaseDownload(fh, request)\n        done = False\n        while not done:\n            _, done = downloader.next_chunk()\n        return fh.getvalue()\n\n    async def _read_impl(self, size: int = -1) -> bytes:\n        \"\"\"Read file content via Google Drive API in a thread pool.\"\"\"","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/connectors/google_drive/_source.py#L106-L142","documentation":"Google Drive files are downloaded whole via the Drive API (export_media or get_media); there is no seekable stream, so the FileLike _read_sync helper only supports reading the entire file (size=-1). Requesting a byte-limited partial read raises ValueError.","triggerScenarios":"Calling read(size=N) with a positive N on a GoogleDrive-backed FileLike object, directly or via code that reads files in chunks.","commonSituations":"Generic file-processing code that reads files in bounded chunks for memory reasons; libraries that probe files with small initial reads; adapting a chunked local-file reader to Google Drive sources.","solutions":["Call read() with no argument (or size=-1) to fetch the entire file, then slice the bytes in memory","Refactor the consumer to accept a full bytes payload instead of chunked reads","Download the file to local storage first and read it with a normal file handle if chunking is essential"],"exampleFix":"// before\ndata = await file.read(size=1024)\n// after\ndata = (await file.read())[:1024]","handlingStrategy":"type-guard","validationCode":"size = getattr(read_call, \"size\", -1)\nif size != -1:\n    raise ValueError(\"Read the whole Google Drive file; partial reads unsupported\")","typeGuard":"def supports_partial_read(f) -> bool:\n    return not hasattr(f, \"_drive_file_id\")  # drive-backed files read whole","tryCatchPattern":"try:\n    data = await file.read(size=n)\nexcept ValueError:\n    data = (await file.read())[:n]","preventionTips":["Read Google Drive files whole and slice in memory","Avoid chunked-read abstractions over drive-backed FileLike objects","Check connector docs for per-source read capabilities before generic readers"],"tags":["google-drive","io","unsupported-operation","file-read"],"backgroundTag":"unsupported-operation","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}