mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-22 09:31:58 -05:00
[PR #24561] [CLOSED] fix: guard metadata chat_id None before startswith in middleware #82597
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/24561
Author: @MikeWang0316tw
Created: 5/11/2026
Status: ❌ Closed
Base:
main← Head:fix/chat-id-none-startswith-error📝 Commits (1)
5bf869ffix: 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
Summary
Fixes
TypeError: 'NoneType' object has no attribute 'startswith'introduced in v0.9.5, which broke all external/api/v1/chat/completionscalls that don't supply achat_id(e.g. IDE extensions, CLI tools, API scripts).Related issues: #24553, #24550, #24554
Root cause
v0.9.5addedchannel:prefix support acrossmiddleware.py. The new code callsmetadata['chat_id'].startswith('channel:')in multiple places, butmetadata['chat_id']isNonewhen the caller does not provide achat_id. This causes:The affected call sites are in
non_streaming_chat_response_handlerandstreaming_chat_response_handler(lines 3062–3064, 3427, 3443, 3466, 3499, 4365, 5043, 5054, 5125).Fix
Replace unguarded
metadata['chat_id'].startswith(...)withmetadata.get('chat_id') and not metadata['chat_id'].startswith(...)so that aNonechat_idis treated as a missing chat session (skip DB persistence), which is the correct behaviour for direct API calls.Test plan
POST /api/v1/chat/completionswithout achat_idfield — should return a valid response instead of 500chat_id— should be unaffectedchat_idstarting withchannel:) — should be unaffected🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.