From 3d43a497b5f4893f2914bc2351034745e05ab2a0 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Wed, 30 Sep 2026 19:03:32 +0200 Subject: [PATCH] fix: shared chats can't open new files attached together with a file already in the chat (#31650) When files were attached to a chat message and one of them was already attached to that chat (on the same message or another one), none of the new files were recorded as part of the chat, and nothing showed up in the logs. The sender still saw every file in their own chat, but anyone opening a shared copy of the chat could not open the new ones. Files already attached to the chat are now skipped and the new ones are recorded normally. Fixes #31648 --- backend/open_webui/models/chats.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/open_webui/models/chats.py b/backend/open_webui/models/chats.py index 76431db97f..a02e4327a4 100644 --- a/backend/open_webui/models/chats.py +++ b/backend/open_webui/models/chats.py @@ -2585,11 +2585,11 @@ class ChatTable: if not file_ids: return None - chat_message_file_ids = { - item.id for item in await self.get_chat_files_by_chat_id_and_message_id(chat_id, message_id, db=db) - } + async with get_async_db_context(db) as session: + result = await session.execute(select(ChatFile.file_id).filter_by(chat_id=chat_id)) + chat_file_ids = set(result.scalars().all()) # Remove duplicates and existing file_ids - file_ids = list({file_id for file_id in file_ids if file_id and file_id not in chat_message_file_ids}) + file_ids = list({file_id for file_id in file_ids if file_id and file_id not in chat_file_ids}) if not file_ids: return None