[PR #24561] [CLOSED] fix: guard metadata chat_id None before startswith in middleware #82597

Closed
opened 2026-05-13 17:08:36 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/open-webui/open-webui/pull/24561
Author: @MikeWang0316tw
Created: 5/11/2026
Status: Closed

Base: mainHead: fix/chat-id-none-startswith-error


📝 Commits (1)

  • 5bf869f fix: 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/completions calls that don't supply a chat_id (e.g. IDE extensions, CLI tools, API scripts).

Related issues: #24553, #24550, #24554

Root cause

v0.9.5 added channel: prefix support across middleware.py. The new code calls metadata['chat_id'].startswith('channel:') in multiple places, but metadata['chat_id'] is None when the caller does not provide a chat_id. This causes:

{"detail":"'NoneType' object has no attribute 'startswith'"}

The affected call sites are in non_streaming_chat_response_handler and streaming_chat_response_handler (lines 3062–3064, 3427, 3443, 3466, 3499, 4365, 5043, 5054, 5125).

Fix

Replace unguarded metadata['chat_id'].startswith(...) with metadata.get('chat_id') and not metadata['chat_id'].startswith(...) so that a None chat_id is treated as a missing chat session (skip DB persistence), which is the correct behaviour for direct API calls.

Test plan

  • Call POST /api/v1/chat/completions without a chat_id field — should return a valid response instead of 500
  • Call via an IDE extension (Continue, OpenCode) — should work as in v0.9.4
  • Normal web UI chat sessions with a chat_id — should be unaffected
  • Channel messages (chat_id starting with channel:) — should be unaffected

🤖 Generated with Claude Code


🔄 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/24561 **Author:** [@MikeWang0316tw](https://github.com/MikeWang0316tw) **Created:** 5/11/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/chat-id-none-startswith-error` --- ### 📝 Commits (1) - [`5bf869f`](https://github.com/open-webui/open-webui/commit/5bf869f8921c2bfc7633f50d82e61155658fd3cf) fix: guard metadata chat_id None before startswith in middleware ### 📊 Changes **1 file changed** (+9 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `backend/open_webui/utils/middleware.py` (+9 -9) </details> ### 📄 Description ## Summary Fixes `TypeError: 'NoneType' object has no attribute 'startswith'` introduced in v0.9.5, which broke all external `/api/v1/chat/completions` calls that don't supply a `chat_id` (e.g. IDE extensions, CLI tools, API scripts). Related issues: #24553, #24550, #24554 ## Root cause `v0.9.5` added `channel:` prefix support across `middleware.py`. The new code calls `metadata['chat_id'].startswith('channel:')` in multiple places, but `metadata['chat_id']` is `None` when the caller does not provide a `chat_id`. This causes: ``` {"detail":"'NoneType' object has no attribute 'startswith'"} ``` The affected call sites are in `non_streaming_chat_response_handler` and `streaming_chat_response_handler` (lines 3062–3064, 3427, 3443, 3466, 3499, 4365, 5043, 5054, 5125). ## Fix Replace unguarded `metadata['chat_id'].startswith(...)` with `metadata.get('chat_id') and not metadata['chat_id'].startswith(...)` so that a `None` `chat_id` is treated as a missing chat session (skip DB persistence), which is the correct behaviour for direct API calls. ## Test plan - [ ] Call `POST /api/v1/chat/completions` without a `chat_id` field — should return a valid response instead of 500 - [ ] Call via an IDE extension (Continue, OpenCode) — should work as in v0.9.4 - [ ] Normal web UI chat sessions with a `chat_id` — should be unaffected - [ ] Channel messages (`chat_id` starting with `channel:`) — should be unaffected 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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-05-13 17:08:36 -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#82597