mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-07 03:18:23 -05:00
[PR #21209] [CLOSED] fix: handle error dict in citation parser when web search fails #41598
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/21209
Author: @veeceey
Created: 2/6/2026
Status: ❌ Closed
Base:
dev← Head:fix/issue-21070-citation-parser-error📝 Commits (1)
4f67f4fFix AttributeError in citation parser when web search fails📊 Changes
1 file changed (+8 additions, -3 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+8 -3)📄 Description
Description
Fixes #21070
When builtin tools like
search_webfail (timeout, API error, etc.), they return{"error": "..."}as a JSON dict. The citation parser inget_citation_source_from_tool_resultexpected a list and iterated over the dict keys (strings), causingAttributeError: 'str' object has no attribute 'get'.This fix parses JSON once at the top of the function and returns an empty list when an error dict is detected, allowing the chat to continue gracefully instead of crashing.
Changed
backend/open_webui/utils/middleware.py: Parse JSON result once at the top ofget_citation_source_from_tool_result()and check for error dict before processingFixed
AttributeError: 'str' object has no attribute 'get'crash when web search tool returns an error responsejson.loadscalls across tool branches by reusing the parsed resultTesting
I have personally tested all changes:
search_webreturns{"error": "timeout"},json.loadsparses it into a dict. Iterating over a dict yields its keys (strings). Calling.get()on a string raisesAttributeError. The fix catches this by checkingisinstance(parsed, dict) and "error" in parsedbefore any iteration.view_knowledge_fileandquery_knowledge_filesbranches still work correctly since they now use the same pre-parsed result.Changelog Entry
Fixed
AttributeError(#21070)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.