fix: prevent recursion error when SharePoint folder is empty#36372
Merged
fatelei merged 1 commit intoMay 20, 2026
Merged
Conversation
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.
Contributor
Pyrefly Type Coverage
|
fatelei
approved these changes
May 20, 2026
zhangtaodemama
added a commit
to zhangtaodemama/langgenius-dify-bfaadcb0c706
that referenced
this pull request
May 20, 2026
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.
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
RecursionErrorwhile maintaining correct behavior for non-empty folders.Fixes #36281