mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[PR #22117] [CLOSED] fix: add type guards in citation parser to prevent AttributeError #26500
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/22117
Author: @umut-polat
Created: 3/1/2026
Status: ❌ Closed
Base:
main← Head:fix/citation-parser-type-guard📝 Commits (1)
7ba2500fix: add type guards in citation parser to prevent AttributeError📊 Changes
1 file changed (+6 additions, -0 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+6 -0)📄 Description
Description
When a tool (e.g.
search_web) returns an error string instead of the expected data structure,get_citation_source_from_tool_resultcrashes with:This happens because the JSON parse failure silently falls through (
pass), leavingtool_resultas a plain string. The code then tries to iterate over the string and call.get()on individual characters.Changes
Added
isinstancetype guards before accessing parsed data in three tool branches:search_web: checkstool_resultis alistbefore iteratingview_knowledge_file: checkstool_resultis adictbefore calling.get()query_knowledge_files: checkstool_resultis alistbefore iteratingReturns an empty source list on type mismatch instead of crashing.
Checklist
Fixes #21070
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.