fix(components): fix Google Drive loader "Include Subfolders" Bad Request and subfolder traversal (#5063) - #6689
Open
ArslanRasheed60 wants to merge 2 commits into
Conversation
…er listing (FlowiseAI#5063) When 'Include Subfolders' is enabled, getFilesFromFolder recurses with a maxFiles budget of (maxFiles - files.length). Once the budget reaches zero, the child call computed pageSize = Math.min(maxFiles - files.length, 1000), which becomes 0 or negative. Google Drive rejects a pageSize outside [1, 1000] with HTTP 400 (Bad Request), surfacing as 'Failed to list files: Bad Request'. Stop issuing a request once the file budget is exhausted and clamp pageSize to a minimum of 1, and skip subfolder recursion when no budget remains.
…lter is set (FlowiseAI#5063) The default fileTypes filter excludes the folder mimeType (application/vnd.google-apps.folder), so the folder listing query never returned subfolders and 'Include Subfolders' silently loaded nothing whenever fileTypes was set (which is the default configuration). When Include Subfolders is enabled, also request the folder mimeType so subfolders can be discovered for recursion, and separate folders out of the returned file list so the fileTypes filter still applies to the loaded files and folders are never treated as loadable documents. Add co-located tests covering the recursive pageSize guard and subfolder traversal under the default fileTypes filter.
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Author
|
Following up on this — would appreciate a review when someone has a chance. Happy to make any changes needed. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Addresses #5063 — "Google Drive Loader: Include Subfolders ON = Bad Request".
Two related defects in the Google Drive document loader (
packages/components/nodes/documentloaders/GoogleDrive/GoogleDrive.ts,getFilesFromFolder) are fixed here. They are split across two commits so each can be weighed independently.Root cause
1. Recursive listing sends an invalid
pageSize→ HTTP 400 (the reported error).When Include Subfolders is ON,
getFilesFromFolderrecurses into each subfolder passing the remaining budget as the child'smaxFiles:The child then builds its page request as:
Once the budget is used up,
maxFiles - files.lengthis0or negative, sopageSizebecomes0/negative. The Google Drive API rejects apageSizeoutside[1, 1000]with HTTP 400 Bad Request, which surfaces as the reported:This only triggers when Include Subfolders is ON, because only recursion shrinks the budget below 1.
2. Subfolders are excluded by the fileTypes filter, so "Include Subfolders" silently does nothing.
The folder listing query applies the
fileTypesfilter:The default
fileTypesdoes not include the folder mimeType (application/vnd.google-apps.folder), so subfolders are never returned by the query and the recursion has nothing to descend into. With the default configuration, "Include Subfolders" therefore loads nothing from subfolders even when the 400 does not fire.The fix
Commit 1 — core (
pageSizeguard):remainingFiles <= 0→ break) instead of sending an invalid page request.pageSizeto a minimum of 1:Math.min(Math.max(remainingFiles, 1), 1000).pageSize.Commit 2 — secondary (subfolder traversal):
fileTypesfilter and can be discovered for recursion.fileTypesfilter still applies to the actual loaded files and folders are never treated as loadable documents.Testing
Added a co-located test suite
GoogleDrive.test.tsthat drives the realgetFilesFromFolderwith a mockedfetchthat emulates the Drive API's mimeType filtering:pageSize <= 0, and does not recurse once the budget is gone. On the pre-fix code this test fails with a recordedpageSizeof-1.fileTypesfilter, subfolders are still traversed and their files collected, while folders themselves are excluded from the returned files. On the pre-fix code this test fails because the subfolder is filtered out and never visited.Verified locally:
pnpm lint(root) — 0 errors.packages/componentsfull Jest suite — the newGoogleDrive.test.tspasses; all suites green (the only failures are the pre-existing Windows-only POSIX-path cases invalidator.test.ts, unrelated to this change).pnpm build(root) — passes.Note for maintainers
This resolves the confirmed Include Subfolders → Bad Request defect (recursion budget →
pageSize <= 0→ Drive 400) and the separate subfolder-skipped-under-default-fileTypes issue. I was not able to reproduce the reporter's exact minimal repro (2 files / default config) purely from source, so I've written this as Addresses #5063 rather than an unqualified "Closes". It may be worth having the reporter confirm their Max Files / File Types configuration so we can be certain their scenario is fully covered.