From 048692c0689511243e3d8f654c482746ae762a81 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Wed, 31 Dec 2025 14:38:57 +0100 Subject: [PATCH] fix: prevent insert_shared_chat_by_chat_id crash when chat is None (#20273) Add null check after db.get(Chat, chat_id) before accessing chat.share_id. Returns None instead of crashing with AttributeError when chat doesn't exist. --- backend/open_webui/models/chats.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/open_webui/models/chats.py b/backend/open_webui/models/chats.py index a8e3d27b9..7848aa89c 100644 --- a/backend/open_webui/models/chats.py +++ b/backend/open_webui/models/chats.py @@ -488,6 +488,9 @@ class ChatTable: with get_db_context(db) as db: # Get the existing chat to share chat = db.get(Chat, chat_id) + # Check if chat exists + if not chat: + return None # Check if the chat is already shared if chat.share_id: return self.get_chat_by_id_and_user_id(chat.share_id, "shared", db=db)