Skip to content

Retry transient Drive API errors on discovery-client calls - #71

Closed
Light2Dark wants to merge 76 commits into
fsspec:masterfrom
marimo-team:sham/add-retries
Closed

Light2Dark wants to merge 76 commits into
fsspec:masterfrom
marimo-team:sham/add-retries

Conversation

@Light2Dark

Copy link
Copy Markdown
Collaborator

Summary

Fixes #21 (partial)

  • Bump _NUM_RETRIES from 2 to 5 and pass num_retries on every googleapiclient .execute() call (list, get, create, delete, trash, drives, about, downloads).
  • Pass num_retries to MediaIoBaseDownload.next_chunk() in export() so chunked exports survive rate limits and 5xx errors.
  • Relies on googleapiclient's built-in backoff, which only retries transient failures (5xx, 429, rate-limit 403s, transport errors) and leaves definitive client errors like 404/permission 403 alone.

Resumable upload HTTP (_authed_request) is intentionally out of scope for this PR.

Checklist

  • Tests added/updated for new behavior
  • Docstrings use RST double backticks for inline code (e.g. drive, not drive)

Made with Cursor

Light2Dark and others added 30 commits June 23, 2026 07:51
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Request mimeType and reject non-folder IDs so a regular file passed as
root_file_id no longer masquerades as an empty directory under ls("").
Add a TODO for the conflicting drive vs shared-drive root_file_id case
(issue #2) to handle in a follow-up.

Co-authored-by: Cursor <cursoragent@cursor.com>
Add integration tests asserting a file ID is rejected as root
(NotADirectoryError) and a folder ID lists its children. Introduce a
typed DriveConfig + make_fs factory fixture in conftest so live
filesystems are built from env in one place and tests can create
multiple instances with a shared teardown. Add tests to pyrefly
search-path and document Drive API constants.

Co-authored-by: Cursor <cursoragent@cursor.com>
Enforce that a scoped drive and root_file_id agree: reject a folder root
whose driveId differs from the configured drive, and raise on a
shared-drive root_file_id that conflicts with an already-set drive
(previously a silent no-op).

Also resolve the `drive` argument by id or name (was name-only) and
correct the docstring accordingly.

Co-authored-by: Cursor <cursoragent@cursor.com>
…tency

Validate drive/root consistency; accept drive id or name
- conftest: collapse unreachable pytest.skip branch in make_fs
- test_core_fs: replace export AttributeError test with strict xfail
  documenting that export() calls a nonexistent path_to_file_id
- test_integration: assert info("") against the real root, not TESTDIR;
  drop dangling issue reference from dircache xfail reason

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Light2Dark and others added 28 commits June 29, 2026 22:29
Update existing files in place instead of creating duplicates (#22)
switch to uv, and modernize CI yaml (fsspec#58)
discard() called a nonexistent self.fs._call, so any transaction
rollback or aborted upload raised AttributeError. Rewrite it to DELETE
the resumable session URI via the owned transport, append
supportsAllDrives, accept Google's 499 cancel status, and clear
self.location. The two existing tests only passed because they
monkeypatched the missing _call in; replace them with real ones.

While adding a multi-chunk integration test (previously commented out),
found that multi-block resumable uploads were silently broken: the code
assumed the server accepted the whole buffer per PUT, but Google only
stores intermediate data up to a 256 KiB-aligned boundary and reports
the real end in the Range header. The old code ignored it and
over-advanced offset, so the final commit never matched and the file
never committed. Add _consume_accepted to re-buffer the unaccepted tail
and return False (fsspec's "buffer not fully consumed" signal), with
guards that raise on protocol-violating responses (no Range, end behind
offset, over-report).

Other changes:
- Replace -O-strippable assert status checks with raise IOError across
  _upload_chunk and _initiate_upload.
- Own the authenticated transport (AuthorizedHttp) instead of reaching
  into the discovery client's private files()._http, sharing one
  transport with build(). No new dependency.
- Add _authed_request wrapper so the untyped transport call returns a
  typed (httplib2.Response, bytes).

Tests: discard/rollback, multi-chunk upload, and the full
_consume_accepted / _parse_range_end branch matrix (unit + live
integration). 121 unit tests pass; 16 integration pass against a live
shared drive.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… cancel

- _parse_range_end: validate the documented bytes=0-<end> shape instead of
  splitting on any dash. A non-zero start, missing dash, or non-integer end
  now returns None, so a malformed/unexpected header re-buffers everything
  rather than miscounting accepted bytes. (cubic + CodeRabbit)
- discard(): force supportsAllDrives=true via a query-aware helper
  (_with_supports_all_drives) instead of a substring check, which previously
  treated supportsAllDrives=false as already set. (CodeRabbit)
- test_transaction_rollback_discards_upload: assert f.location is None after
  rollback to prove the resumable session was actually cancelled, not just
  that the file was never committed. (cubic + CodeRabbit)

Added unit tests for both helpers (non-zero-start/garbled ranges; the
=false override case).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The final chunk sends a concrete total (bytes X-Y/total) and expects a
200/201 that commits the object. A 308 there means the server did NOT
finalize, but it was funneled into _consume_accepted as if it were a
normal partial-consumption signal. Since commit()/close() flush exactly
once and ignore the return, that left the upload unfinalized (file_id
unset) while the handle closed — silently.

Raise IOError when final=True (and autocommit, i.e. we sent a concrete
total) and the server returns 308. The condition mirrors the
concrete-total header branch, so intermediate wildcard chunks still
re-buffer as before.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
add a comment, and do a small test cleanup
fix cache stashing and retrieval
PR #51 (merged from master) added test_rm_deletes_file and
test_rmdir_deletes_empty_directory that mock info() without
capabilities, tripping the canDelete check in _rm. Provide
deletable capabilities via the existing _deletable_info helper.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- _info_by_id: drop reserved keys (fileId/fields/supportsAllDrives) from
  forwarded **kwargs to avoid TypeError
- ls/info: normalize a blank/whitespace field mask to None so it keeps the
  cache fast path instead of forcing a fresh listing / files.get
- _rm: raise ValueError on the filesystem root instead of a misleading
  PermissionError
- use a relative import for utils; readonly_fs skips without GDRIVE_FSSPEC_DRIVE

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Permission-aware rm and dircache correctness fixes
* add multiple profiles testing

* add back removed

* update docstring

* fix lint
@Light2Dark

Copy link
Copy Markdown
Collaborator Author

Closing — opened against the wrong repo. Retargeting to marimo-team/gdrive-fsspec main.

@Light2Dark Light2Dark closed this Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Any plans on making a release / publishing the package on PyPI

1 participant