Skip to content

Comments

fix: prevent RuntimeError in process_metadata when excluding keys#21105

Merged
tjbck merged 1 commit intoopen-webui:devfrom
Classic298:patch-3
Feb 13, 2026
Merged

fix: prevent RuntimeError in process_metadata when excluding keys#21105
tjbck merged 1 commit intoopen-webui:devfrom
Classic298:patch-3

Conversation

@Classic298
Copy link
Collaborator

Fixed process_metadata function that would raise RuntimeError: dictionary changed size during iteration when 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:

  1. Multitenancy mode users - The multitenancy Milvus client (and others) doesn't call process_metadata at all, passing metadata directly without processing.

  2. Standard mode users - Before metadata reaches process_metadata, it passes through filter_metadata first (in process_file), which already removes the excluded keys. By the time process_metadata is called, those keys are already gone.

  3. 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 AzureAIDocumentIntelligenceLoader might 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:

  • A new code path calls process_metadata directly without prior filtering
  • A new document loader returns metadata with these keys
  • Someone refactors the existing flow and removes the upstream filter_metadata call

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

Note

Deleting the CLA section will lead to immediate closure of your PR and it will not be merged in.

@pr-validator-bot
Copy link

👋 Welcome and Thank You for Contributing!

We appreciate you taking the time to submit a pull request to Open WebUI!

⚠️ Important: Testing Requirements

We've recently seen an increase in PRs that have significant issues:

  • PRs that don't actually fix the bug they claim to fix
  • PRs that don't implement the feature they describe
  • PRs that break existing functionality
  • PRs that are clearly AI-generated without proper testing being done by the author
  • PRs that simply don't work as intended

These untested PRs consume significant time from maintainers and volunteer contributors who review and test PRs in their free time.
Time that could be spent testing other PRs or improving Open WebUI in other ways.

Before marking your PR as "Ready for Review":

Please explicitly confirm:

  1. ✅ You have personally tested ALL changes in this PR
  2. How you tested it (specific steps you took to verify it works)
  3. Visual evidence where applicable (screenshots or videos showing the feature/fix working) - if applicable to your specific PR

If you're not certain your PR works exactly as intended, please leave it in DRAFT mode until you've thoroughly tested it.

Thank you for helping us maintain quality and respecting the time of our community! 🙏

@tjbck
Copy link
Contributor

tjbck commented Feb 13, 2026

Thanks!

@tjbck tjbck merged commit 97a3b15 into open-webui:dev Feb 13, 2026
0 of 2 checks passed
@Classic298 Classic298 deleted the patch-3 branch February 13, 2026 20:02
iccyuan pushed a commit to iccyuan/open-webui that referenced this pull request Feb 14, 2026
hsmallbone pushed a commit to hsmallbone/open-webui that referenced this pull request Feb 14, 2026
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.

3 participants