Repository navigation
Recursive get and copy use the IDs from their listing, without a lookup per file - #468
shcheklein wants to merge 9 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A recursive get or copy listed the tree and then looked every file up by name again: 2,007 requests for 1,000 files where 1,006 do. The IDs the listing returns are kept on the calling thread until the call returns. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
AI generated · Claude · The new live tests on main's code, on real Drive: the test commit alone (417ae10) on a temporary branch, run by hand. Ubuntu 3.11 job. The run was cancelled after this job, and the branch deleted. On main, the recursive |
There was a problem hiding this comment.
🟡 Changes recommended
Transfer ID caching can select a folder instead of the intended same-name file, while nested transfers reuse and contaminate the outer ID map, risking stale reads or failures.
2 open issues
What changed in this PR
This PR reduces Drive requests by reusing listing IDs during recursive and glob-based filesystem transfers.
Changes:
- Reuses thread-local IDs during
getandcopy. - Translates copy-request 404 errors to
FileNotFoundError. - Adds transfer tests and documents concurrent-change behavior.
| File | Description |
|---|---|
pydrive2/test/test_fs.py |
Adds live request-count, duplicate-name, and deletion tests. |
pydrive2/test/test_fs_unit.py |
Updates expected transfer request counts. |
pydrive2/fs/spec.py |
Reuses listed IDs and translates copy errors. |
docs/fsspec.rst |
Documents ID lifetime and deletion behavior. |
Review effort: Balanced
The start of a recursive call came from a folders-only lookup, so an older file of the same name could lose to the folder; its lookup is served from the folder cache anyway. A get or copy started from a callback now lists with its own IDs instead of the outer call's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A lookup splits paths at slashes, so it cannot reach a Drive name such as "../escaped.txt" or anything below a folder named "x/y". Remembering those let a recursive get or copy reach them by ID, and an older fsspec then wrote "../escaped.txt" above the target. They now go through the lookup as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because copy-error handling can misclassify destination failures as missing sources, silently skipping existing files during recursive copies.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
A 404 on the copy request also comes when the destination folder was removed. Main raised Drive's error then, and a recursive copy would now have skipped the file. On a 404 the source is checked by ID, and only a missing source becomes FileNotFoundError. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
AI generated · Claude · On the third review's summary, "copy-error handling can misclassify destination failures as missing sources": agreed, and fixed in the latest commit. A 404 on the copy request also comes when the destination folder was removed. Main raised Drive's error in that case, while b51b634 turned it into |
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because an unpublished finding identifies documentation that could mislead callers about detecting incomplete recursive copies when deleted sources are skipped by default.
No open issues 🎉
Review effort: Balanced
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
AI generated · Claude · On the fourth review's summary, about the documentation and skipped deleted sources: agreed. The guide said a file deleted mid-call raises |
shcheklein
left a comment
There was a problem hiding this comment.
Codex review of the listed-ID transfer change. I verified the behavior in the inline findings with fsspec 2024.2.0 and 2026.9.0.
get() and copy() run fsspec's code against a view that records what its own listings return. The view answers the isdir() filter, get_file() and cp_file() from that record, so a glob sends no lookup per match. Callbacks reach the filesystem itself and look paths up again. A listed item with several parents turns the record off, because a listing of several folders places it under only one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shcheklein
left a comment
There was a problem hiding this comment.
Codex re-review of 9e85e42. The updated implementation addresses the five earlier comments. I reproduced the four findings below with fsspec 2024.2.0 and 2026.9.0. The filesystem unit suite passed on both versions.
A subclass that overrides a hook the transfer replaces keeps fsspec's own transfer. The copy destination is checked as before, the ID hint goes through private helpers after the path is validated, and the listing and the record share each path string. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>


A recursive
getorcopylists the tree, which already returns every file's Drive ID. It then looked each file up by name again before downloading or copying it:For a folder with 1,000 files and a subfolder with one more:
fs.get("root/data", "local/", recursive=True)findsends, plus one download per file)fs.copy("root/data", "root/copy", recursive=True)fs.get("root/data/*.csv", "local/")with 1,000 matchesThe glob row follows from an offline count with three matches: 14 requests before, 5 after.
rclone does the same: a listed object is opened by its listed ID (
files/<id>?alt=media), with no lookup per file.How
getandcopyrun fsspec's own code against a view of the filesystem made for that one call (_ListedTransfer). The view'sfindrecords the ID and type of each listed path. Itsisdir,get_fileandcp_fileanswer from that record, so fsspec's type filter for globs andmaxdepthand each transfer need no lookup. Same-name files keep the lowest-ID rule, so the result is the file a lookup of that path would pick.Some cases fall back to lookups:
../escaped.txtwould be found by its listed ID, and with an fsspec older than its destination check, a recursivegetwould write it above the target.expand_path,glob,find,isdir,get_fileorcp_filegets fsspec's plain transfer.The folder a call starts from is looked up as before; the folder cache that
findjust filled answers that lookup, so it costs no request. Callbacks get the filesystem itself, so afind,get_fileor nestedgetthey call looks paths up again. The ID hint reaches private helpers only, after the path is validated, so the public methods keep their signatures.getandcopyusefunctools.wraps, soinspect.signatureshows fsspec's options.Nothing is kept after the call returns, and other calls on the same filesystem never see the record. It takes about 160 bytes per file while the call runs: 151 to 159 bytes measured on Python 3.11, 3.13 and 3.15 with 5,000 paths and 33-character IDs. The record shares its path strings with the listing result that fsspec holds anyway.
Behaviour change
Inside one call, a file is read by the ID it had when it was listed:
FileNotFoundError, as before. A recursivecopyskips it, as before. When a copy request gets 404, the source is checked by ID (one request, only then). Only a missing source becomesFileNotFoundError; a 404 because the destination folder disappeared still raises Drive's error, as on main.docs/fsspec.rstdescribes this under "Directory cache".Not covered
These still look each file up by name:
find()followed byget_file()calls;get_file(dvc-objectsgeneric._get) and never calls a recursiveget;rm, uploads, andget/copycalled with lists of paths, which skip fsspec's listing.Tests
Live, on real Drive. A shared tree holds a file, a subfolder with a file, and two files of one name created through the core API.
get: sends exactly whatfindsends for the same tree, plus one download per file. The same-name file is the onecat_filereturns.getof a glob: sends exactly whatglobsends, plus one download per match.copy: never searches Drive for a source file's name and sends one copy per file.getraiseFileNotFoundError.copyof a tree holding../escaped.txtand a folderx/ywith a file inside copies only what a lookup finds, as on main.Offline, for what real Drive can't be made to send on demand:
get_filelooks the path up again;globkeeps only CSV files downloads only those;FileNotFoundErrorfromcp_filewhen the source is gone, and Drive's error when the source still exists;copyskips a deleted source and copies the rest.On main's code, the
getcount test (10 requests where 7 are expected) and thecopytest (searches for'same.txt') fail. That was checked on the fake Drive harness, and the result of the same run on real Drive is in the first comment. Two offline tests that counted the old lookup now count the new requests.Conflicts with open PRs
Textual conflicts are likely in
pydrive2/fs/spec.pywith #453, #455 and #456, all of which editfind,_lookup_item,cp_fileor nearby code. They're also likely at the end of the get tests inpydrive2/test/test_fs.py. #456 changes howget_filedownloads but not how it finds the ID, so the two compose: a recursivegetbecomes one streamed download per file.answered_requestsis one more copy of the HTTP-observing fixture that #464 plans to merge into one.🤖 Generated with Claude Code