Skip to content

fix: prevent recursion error when SharePoint folder is empty#36372

Merged
fatelei merged 1 commit into
langgenius:mainfrom
EvanYao826:fix/sharepoint-empty-folder-recursion
May 20, 2026
Merged

fix: prevent recursion error when SharePoint folder is empty#36372
fatelei merged 1 commit into
langgenius:mainfrom
EvanYao826:fix/sharepoint-empty-folder-recursion

Conversation

@EvanYao826
Copy link
Copy Markdown
Contributor

Summary

Fixes a recursion error that occurs in the RAG pipeline when a SharePoint folder is empty. The issue causes the SharePoint document loader to enter an infinite recursive loop when traversing folders that contain no items, eventually leading to a RecursionError (maximum recursion depth exceeded).

Problem

When the SharePoint data source connector encounters an empty folder during document synchronization, the recursive folder traversal logic does not handle the case where a folder returns zero items. This results in an infinite loop that exhausts the Python call stack.

Solution

Added a base-case check before recursing into subfolders: if a folder returns no items, the recursion terminates early instead of attempting to process the empty result set again. This prevents the RecursionError while maintaining correct behavior for non-empty folders.

Fixes #36281

Fixes langgenius#36281

When an empty SharePoint folder was selected as a data source in the RAG
pipeline, _get_files_in_folder would recurse infinitely in two scenarios:

1. Self-referencing folders: the API returns the folder as its own child
   entry with type='folder', causing the method to call itself with the
   same folder ID forever.

2. Empty folder with false truncation: the API returns no files but sets
   is_truncated=True, causing the method to re-query the same empty page
   in an infinite loop.

Fix by adding a visited-folder-ID set to detect self-references, and a
guard that only follows pagination when the API actually returned files.
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 0.00% 44.42% +44.42%
Strict coverage 0.00% 43.94% +43.94%
Typed symbols 0 22,535 +22,535
Untyped symbols 0 28,504 +28,504
Modules 0 2561 +2,561

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 20, 2026
@fatelei fatelei added this pull request to the merge queue May 20, 2026
Merged via the queue into langgenius:main with commit 7bc5c89 May 20, 2026
27 checks passed
zhangtaodemama added a commit to zhangtaodemama/langgenius-dify-bfaadcb0c706 that referenced this pull request May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SharePoint empty folder as data source, recursion error

2 participants