mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-23 01:51:58 -05:00
[PR #24563] [CLOSED] fix: guard metadata chat_id None before startswith in middleware #115035
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/24563
Author: @MikeWang0316tw
Created: 5/11/2026
Status: ❌ Closed
Base:
dev← Head:fix/chat-id-none-startswith-error-dev📝 Commits (1)
6884d59fix: guard metadata chat_id None before startswith in middleware📊 Changes
1 file changed (+9 additions, -9 deletions)
View changed files
📝
backend/open_webui/utils/middleware.py(+9 -9)📄 Description
Before submitting, make sure you've checked the following:
dev'NoneType' object has no attribute 'startswith'regression in v0.9.5POST /api/v1/chat/completionswithoutchat_idnow works; web UI chat sessions unaffectedChangelog Entry
Description
v0.9.5introducedchannel:prefix support inmiddleware.py, adding multiplemetadata['chat_id'].startswith('channel:')calls. When/api/v1/chat/completionsis called from an external client without achat_idfield (IDE extensions, CLI tools, API scripts),metadata['chat_id']isNone, causing:The web UI is unaffected because browser sessions always supply
chat_id. Only headless / programmatic API callers are impacted.Fixed
middleware.py: replaced unguardedmetadata['chat_id'].startswith(...)withmetadata.get('chat_id') and not metadata['chat_id'].startswith(...)at 9 call sites innon_streaming_chat_response_handlerandstreaming_chat_response_handler. ANonechat_idnow correctly skips DB persistence, matching the behaviour for requests without a session.Reproduce before fix
After fix: returns a valid completion response.
Contributor License Agreement
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.