Description
Uploads of larger spreadsheet files were intermittently failing with 500 Internal Error responses from the Google Drive API. Smaller files were less affected, making the behavior appear inconsistent.
Root Causes
Unnecessary use of convert=True
Using convert=True when updating existing Google Sheets caused instability. This flag is only needed to convert non-Google files (e.g., .xlsx) into Google Sheets, however, in the case of larger files it seems unstable.
- Missing buffer reset
(seek(0))
Spreadsheet content is generated in memory using a BytesIO object. After writing, the pointer is at the end. Without seek(0), uploads could send incomplete or bad data. The issue was worse for larger files and often produced the error 500.
- Non-deterministic behavior of Drive API v2
Uploads could succeed or fail depending on file size or backend state, highlighting instability and the need for retries. The main reason is that PyDrive does only support V2 API. Meanwhile the current API is at v3. As per this post.
Additional Context
PyDrive relies on Google Drive API v2, which is deprecated:
- Weak error handling (generic 500 responses)
- Inconsistent behavior for conversions and uploads
PyDrive itself is obsolete:
- Not maintained since 2021
- Archived on GitHub
- Reduces visibility into what API calls are actually executed or errors raised.
Recommendation
Migrate gitmetrics to use the official Google API directly.
Benefits:
- Full control over API calls
- Use of the latest API version
- Improved reliability and clearer error reporting
- More stable and maintained API.
Description
Uploads of larger spreadsheet files were intermittently failing with
500 Internal Errorresponses from the Google Drive API. Smaller files were less affected, making the behavior appear inconsistent.Root Causes
Unnecessary use of convert=TrueUsing
convert=Truewhen updating existing Google Sheets caused instability. This flag is only needed to convertnon-Googlefiles (e.g.,.xlsx) into Google Sheets, however, in the case of larger files it seems unstable.(seek(0))Spreadsheet content is generated in memory using a
BytesIOobject. After writing, the pointer is at the end. Withoutseek(0), uploads could send incomplete or bad data. The issue was worse for larger files and often produced the error 500.Uploads could succeed or fail depending on file size or backend state, highlighting instability and the need for retries. The main reason is that
PyDrivedoes only support V2 API. Meanwhile the current API is at v3. As per this post.Additional Context
PyDrive relies on Google Drive API v2, which is deprecated:
PyDrive itself is obsolete:
Recommendation
Migrate gitmetrics to use the official Google API directly.
Benefits: