[PR #16454] [CLOSED] fix: Handle JSONResponse objects in middleware to prevent TypeError #47188

Closed
opened 2026-04-29 22:17:49 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/16454
Author: @jamesmalin
Created: 8/10/2025
Status: Closed

Base: mainHead: fix/jsonresponse-middleware-error


📝 Commits (1)

  • c90f953 fix: Handle JSONResponse objects in middleware to prevent TypeError

📊 Changes

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

View changed files

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

📄 Description

Fixes #16452

Problem

The middleware was attempting to use the 'in' operator and .get() method directly on JSONResponse objects, causing TypeErrors when the API returned error responses.

Solution

Added isinstance(response, dict) checks before using 'in' operator and calling .get() method to ensure operations are only performed on dictionary objects.

Changes

  • Modified process_chat_response() function in backend/open_webui/utils/middleware.py
  • Added defensive programming to handle both dict and JSONResponse objects

Testing

  • Tested with OpenAI API error responses
  • Confirmed proper error handling without system crashes
  • Verified normal operation with successful responses

🔄 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/16454 **Author:** [@jamesmalin](https://github.com/jamesmalin) **Created:** 8/10/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/jsonresponse-middleware-error` --- ### 📝 Commits (1) - [`c90f953`](https://github.com/open-webui/open-webui/commit/c90f953309afb5ae415f774a60600d8410e4f871) fix: Handle JSONResponse objects in middleware to prevent TypeError ### 📊 Changes **1 file changed** (+3 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/middleware.py` (+3 -3) </details> ### 📄 Description Fixes #16452 ## Problem The middleware was attempting to use the 'in' operator and .get() method directly on JSONResponse objects, causing TypeErrors when the API returned error responses. ## Solution Added isinstance(response, dict) checks before using 'in' operator and calling .get() method to ensure operations are only performed on dictionary objects. ## Changes - Modified process_chat_response() function in backend/open_webui/utils/middleware.py - Added defensive programming to handle both dict and JSONResponse objects ## Testing - Tested with OpenAI API error responses - Confirmed proper error handling without system crashes - Verified normal operation with successful responses --- <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-29 22:17:50 -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#47188