mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #21250] [CLOSED] fix: handle error dict in citation parser when web search fails #41624
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/21250
Author: @veeceey
Created: 2/8/2026
Status: ❌ Closed
Base:
dev← Head:fix/issue-21070-citation-parser-error-v2📝 Commits (1)
fb510abFix 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
Pull Request Checklist
devbranch.fix:to categorize this pull request.Changelog Entry
Description
Fixes
AttributeError: 'str' object has no attribute 'get'crash in citation parser when builtin tools likesearch_webfail (timeout, API error, etc.). When tools fail, they return{"error": "..."}as a JSON dict. The citation parser expected a list and iterated over the dict keys (strings), causing the AttributeError. 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.Supersedes #21207 (closed due to missing CLA and wrong target branch).
Fixes #21070
Changed
backend/open_webui/apps/webui/routers/utils.py:get_citation_source_from_tool_result(){"error": "..."}is foundjson.loadscallsFixed
AttributeError: 'str' object has no attribute 'get'crash when web search or other builtin tools failAdditional Information
Root Cause
When builtin tools like
search_webfail (timeout, API error, network issue, etc.), they return:The citation parser in
get_citation_source_from_tool_resultexpected the result to be a list like:When it received an error dict instead, it iterated over the dict keys (
["error"]), treating them as citation objects. When it tried to calltag.get('name')on the string"error", it crashed withAttributeError.Solution
Screenshots or Videos
Test Results
Scenario 1: Web search API timeout
AttributeError: 'str' object has no attribute 'get', conversation cannot continueScenario 2: Web search API error (invalid key, rate limit, etc.)
Scenario 3: Normal web search with valid results
Scenario 4:
view_knowledge_fileandquery_knowledge_filestoolsTesting method:
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.