Skip to content

Treat a trashed folder ID used as the root as missing - #451

Draft
shcheklein wants to merge 5 commits into
mainfrom
trashed-root-raises
Draft

shcheklein wants to merge 5 commits into
mainfrom
trashed-root-raises

Conversation

@shcheklein

@shcheklein shcheklein commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

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 trash
fs.info("1AbC...")                    # FileNotFoundError
fs.ls("1AbC...")                      # ['1AbC.../a.txt'] before, FileNotFoundError now
list(fs.walk("1AbC..."))              # [('1AbC...', [], ['a.txt'])] before, [] now
fs.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).

🤖 Generated with Claude Code

shcheklein and others added 2 commits December 2, 2026 19:12
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>
Comment thread pydrive2/fs/spec.py Resolved
Comment thread pydrive2/test/test_fs.py Resolved

@shcheklein shcheklein left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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.

Comment thread pydrive2/fs/spec.py Resolved
Comment thread pydrive2/test/test_fs.py Resolved
shcheklein and others added 2 commits December 3, 2026 11:05
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

1 open issue
What changed in this PR

This PR makes trashed folder-ID roots behave as missing paths in the Google Drive filesystem, including lookups beneath them.

Changes:

  • Centralizes trash checks and applies them before listing.
  • Adds live coverage for fresh filesystems and cache invalidation.
  • Adds offline coverage for children that Drive still lists after trashing.
File Description
pydrive2/​test/​test_fs.py Adds live regression coverage for trashed roots and children.
pydrive2/​test/​test_fs_unit.py Tests descendant rejection before listing requests.
pydrive2/​fs/​spec.py Shares and extends root metadata trash checks.

Review effort: Balanced

Comment thread pydrive2/fs/spec.py Resolved
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Medium severity 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).

1 resolved since last review

Review effort: Balanced

@shcheklein

Copy link
Copy Markdown
Member Author

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
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.

2 participants