mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-05 18:38:17 -05:00
[PR #21105] [MERGED] fix: prevent RuntimeError in process_metadata when excluding keys #41561
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/21105
Author: @Classic298
Created: 2/2/2026
Status: ✅ Merged
Merged: 2/13/2026
Merged by: @tjbck
Base:
dev← Head:patch-3📝 Commits (1)
119c229Update utils.py📊 Changes
1 file changed (+10 additions, -10 deletions)
View changed files
📝
backend/open_webui/retrieval/vector/utils.py(+10 -10)📄 Description
Fixed
process_metadatafunction that would raiseRuntimeError: dictionary changed size during iterationwhen metadata contained any of the excluded keys (content,pages,tables,paragraphs,sections,figures).The function was deleting keys while iterating over
dict.items(), which invalidates the iterator in Python 3. Now builds a new dict instead of mutating the original.Why this has never been reported
This bug has never surfaced in practice due to how the code paths are structured:
Multitenancy mode users - The multitenancy Milvus client (and others) doesn't call
process_metadataat all, passing metadata directly without processing.Standard mode users - Before metadata reaches
process_metadata, it passes throughfilter_metadatafirst (inprocess_file), which already removes the excluded keys. By the timeprocess_metadatais called, those keys are already gone.Document loaders - The custom loaders (MinerU, Mistral OCR, Datalab Marker, Docling, Tika) don't include these keys in their metadata output. Only certain LangChain loaders like
AzureAIDocumentIntelligenceLoadermight return them, but they get filtered upstream.Why it should still be fixed
Despite being unreachable in current code paths, this is a latent bug that could cause failures if:
process_metadatadirectly without prior filteringfilter_metadatacallFixing it ensures the function works correctly in isolation, as its signature and docstring imply it should.
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.