From e288cdc4700c8e9c9bb8801e2d23ea5e45b02390 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Tue, 3 Nov 2026 19:48:29 +0100 Subject: [PATCH] fix: chat read limit failing on chats with empty or non-text messages With a chat read limit set, reading an imported chat that held empty or non-text message content ended in an error instead of the chat. Such content is now counted and cut as plain text. --- backend/open_webui/tools/builtin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/tools/builtin.py b/backend/open_webui/tools/builtin.py index 9534466fd4..66b340b255 100644 --- a/backend/open_webui/tools/builtin.py +++ b/backend/open_webui/tools/builtin.py @@ -1752,13 +1752,13 @@ async def view_chat( truncation = {} max_chars = await Config.get('chats.view_max_chars') - if max_chars and sum(len(message['content']) for message in messages) > max_chars: + if max_chars and sum(len(str(message['content'] or '')) for message in messages) > max_chars: remaining_chars = max_chars kept_messages = [] for message in messages: if remaining_chars <= 0: break - content = message['content'][:remaining_chars] + content = str(message['content'] or '')[:remaining_chars] kept_messages.append({**message, 'content': content}) remaining_chars -= len(content) truncation = {