[PR #21207] [CLOSED] fix: handle error dict in citation parser when web search fails #49014

Closed
opened 2026-04-30 01:19:28 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/21207
Author: @veeceey
Created: 2/6/2026
Status: Closed

Base: mainHead: fix/issue-21070-citation-parser-error


📝 Commits (1)

  • 7b0442c fix: handle error dict responses in citation parser to prevent AttributeError

📊 Changes

1 file changed (+8 additions, -3 deletions)

View changed files

📝 backend/open_webui/utils/middleware.py (+8 -3)

📄 Description

Summary

  • When builtin tools like search_web fail (timeout, API error, etc.), they return {"error": "..."} as a JSON dict. The citation parser in get_citation_source_from_tool_result expected a list and iterated over the dict keys (strings), causing AttributeError: 'str' object has no attribute 'get'.
  • Parse JSON once at the top of the function and return an empty list when an error dict is detected, allowing the chat to continue gracefully.
  • Also reuses the parsed JSON result across all tool branches, eliminating redundant json.loads calls.

Fixes #21070

Test plan

  • Configure web search with a search engine, then trigger a search while the API is unavailable/times out. Verify the chat continues without crashing.
  • Verify normal web search still produces citations correctly.
  • Verify view_knowledge_file and query_knowledge_files citations still work correctly.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/open-webui/open-webui/pull/21207 **Author:** [@veeceey](https://github.com/veeceey) **Created:** 2/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/issue-21070-citation-parser-error` --- ### 📝 Commits (1) - [`7b0442c`](https://github.com/open-webui/open-webui/commit/7b0442c7d88eeb223914a8d9d3f7a775e29f4b01) fix: handle error dict responses in citation parser to prevent AttributeError ### 📊 Changes **1 file changed** (+8 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/middleware.py` (+8 -3) </details> ### 📄 Description ## Summary - When builtin tools like `search_web` fail (timeout, API error, etc.), they return `{"error": "..."}` as a JSON dict. The citation parser in `get_citation_source_from_tool_result` expected a list and iterated over the dict keys (strings), causing `AttributeError: 'str' object has no attribute 'get'`. - Parse JSON once at the top of the function and return an empty list when an error dict is detected, allowing the chat to continue gracefully. - Also reuses the parsed JSON result across all tool branches, eliminating redundant `json.loads` calls. Fixes #21070 ## Test plan - [ ] Configure web search with a search engine, then trigger a search while the API is unavailable/times out. Verify the chat continues without crashing. - [ ] Verify normal web search still produces citations correctly. - [ ] Verify `view_knowledge_file` and `query_knowledge_files` citations still work correctly. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-30 01:19:28 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/open-webui#49014