You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Treat a trashed folder ID used as the root as missing - #451
A filesystem whose root is a folder ID kept listing that folder after it was moved to the trash. info() already said it was gone.
Example
fs=GDriveFileSystem("1AbC...") # a folder ID; the folder is in the trashfs.info("1AbC...") # FileNotFoundErrorfs.ls("1AbC...") # ['1AbC.../a.txt'] before, FileNotFoundError nowlist(fs.walk("1AbC...")) # [('1AbC...', [], ['a.txt'])] before, [] nowfs.cat_file("1AbC.../a.txt") # b"a" before, FileNotFoundError now
A sync job that lists the folder kept seeing its files, or nothing to do, instead of an error.
The rule
A trashed folder ID is a missing path, in every call. For a missing path:
ls() and info() raise FileNotFoundError, and exists() is false, for the folder and for every path under it;
find() and walk() return nothing; fsspec does that for every missing path, and other code relies on it.
How
The filesystem reads a folder ID root's metadata before its first listing, and again after invalidate_cache(). Some calls checked its trashed flag; ls() of the root did so only when the root was a file, and paths under the root never did. Every call that reads the root's metadata now checks it, through one helper. That includes the listing parameters, which every lookup under the root uses.
Checking the children instead does not work on real Drive. Right after a folder is trashed, its children still list for a while as not trashed. The first version of this PR did that, and the live tests caught it.
A filesystem that had already listed the folder before another client trashed it keeps using its cache. The guide's rule for other changes by other clients applies: call fs.invalidate_cache(), after which the folder is missing in every call.
Validation
Live, on real Drive, one test with a folder that holds one file. A filesystem lists the folder, another client trashes it, and then both that filesystem after invalidate_cache() and a new one must find the folder and its file missing: ls(), info() and cat_file() raise, exists() is false, and find() of either and walk() return nothing.
Offline, the window Drive cannot be made to show on demand: the root is trashed while Drive still lists its file. info(), ls() and cat_file() of the file raise, and find() of it returns nothing, without sending the listing. They fail without the fix.
The offline suite passes with the current google-auth and with 2.15.0 (541 passed).
A filesystem on a folder ID listed a trashed folder as empty, while
info() raised FileNotFoundError. ls() now raises too: an empty listing
of the root checks that the folder is not trashed. find() and walk()
return nothing, as for any missing path.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On real Drive the children of a folder that was just trashed still
list for a while, so an empty listing did not show that the root was
trashed. ls() of a folder ID root now raises when the root's metadata
says it is trashed, as info() does. A filesystem that listed the
folder before learns of the change when its cache is invalidated, as
the guide says for other changes made by other clients.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
[AI generated — Copilot]
5-pass review summary: fixes ls(folder_id) on a trashed folder ID root, but subpaths under a trashed folder ID still bypass the check via _list_params, and the trashed check is now duplicated across 5 call sites.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
When the root is trashed, fs.find("FolderID/a.txt") on a new filesystem or after invalidate_cache() raises FileNotFoundError instead of returning [] (or {} with detail=True). Descendant resolution fails before find() reaches its missing-path handlers.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
For a named mount such as GDriveFileSystem("FolderID/sub", ...), find("FolderID/sub/a.txt") should return an empty result when FolderID is trashed, but it still raises because _resolver() resolves self.base before entering the exception handler. This affects both fresh instances and instances whose cache has been invalidated.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Handle trashed mount resolution errors in find
pydrive2/fs/spec.py:1162
For a named mount such as GDriveFileSystem("FolderID/sub", ...), find("FolderID/sub/a.txt") still raises when FolderID is trashed. _resolver() eagerly resolves self.base, reaching the new trash check before this try block, both on a fresh instance and after cache invalidation. Move resolver creation inside the handler too, so these searches return [] (or {} with detail=True).
AI generated · Claude · Re Copilot's "Handle trashed mount resolution errors in find" (review on eda256b): keeping it as it is.
With a mount such as GDriveFileSystem("FolderID/sub"), a trashed FolderID means the mount itself is missing. find already raises FileNotFoundError for a missing mount: on main, _resolver() raises it when sub is deleted, before any find handling. This PR makes the trashed case match that, and it now stops after the one metadata request without listing the trashed folder. I checked both cases offline against eda256b: each raises FileNotFoundError.
Moving _resolver() inside the handler would also make find return [] for a mount whose base path was deleted. That would change existing behaviour for missing mounts, which is outside this PR. find returns empty only when the mount resolves and the searched path under it is missing.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A filesystem whose root is a folder ID kept listing that folder after it was moved to the trash.
info()already said it was gone.Example
A sync job that lists the folder kept seeing its files, or nothing to do, instead of an error.
The rule
A trashed folder ID is a missing path, in every call. For a missing path:
ls()andinfo()raiseFileNotFoundError, andexists()is false, for the folder and for every path under it;find()andwalk()return nothing; fsspec does that for every missing path, and other code relies on it.How
The filesystem reads a folder ID root's metadata before its first listing, and again after
invalidate_cache(). Some calls checked itstrashedflag;ls()of the root did so only when the root was a file, and paths under the root never did. Every call that reads the root's metadata now checks it, through one helper. That includes the listing parameters, which every lookup under the root uses.Checking the children instead does not work on real Drive. Right after a folder is trashed, its children still list for a while as not trashed. The first version of this PR did that, and the live tests caught it.
A filesystem that had already listed the folder before another client trashed it keeps using its cache. The guide's rule for other changes by other clients applies: call
fs.invalidate_cache(), after which the folder is missing in every call.Validation
invalidate_cache()and a new one must find the folder and its file missing:ls(),info()andcat_file()raise,exists()is false, andfind()of either andwalk()return nothing.info(),ls()andcat_file()of the file raise, andfind()of it returns nothing, without sending the listing. They fail without the fix.🤖 Generated with Claude Code