From 0ab3a2b33545d5af32a670381a8797c783e5c15e Mon Sep 17 00:00:00 2001 From: G30 <50341825+silentoplayz@users.noreply.github.com> Date: Wed, 23 Sep 2026 23:32:54 -0400 Subject: [PATCH] fix: restore tag rows after unarchiving all chats and remove unused ones after deleting all chats (#30453) --- backend/open_webui/routers/chats.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/open_webui/routers/chats.py b/backend/open_webui/routers/chats.py index ed339a601a..7138dc9f21 100644 --- a/backend/open_webui/routers/chats.py +++ b/backend/open_webui/routers/chats.py @@ -716,8 +716,10 @@ async def delete_all_user_chats( detail=ERROR_MESSAGES.ACCESS_PROHIBITED, ) + tag_ids = [tag.id for tag in await Tags.get_tags_by_user_id(user.id, db=db)] result = await Chats.delete_chats_by_user_id(user.id, db=db) if result: + await Chats.delete_orphan_tags_for_user(tag_ids, user.id, db=db) await publish_event( request, EVENTS.CHAT_DELETED_ALL, @@ -1129,8 +1131,14 @@ async def archive_all_chats( async def unarchive_all_chats( request: Request, user=Depends(get_verified_user), db: AsyncSession = Depends(get_async_session) ): + tag_ids = { + tag_id + for chat in await Chats.get_archived_chats_by_user_id(user.id, db=db) + for tag_id in chat.meta.get('tags', []) + } result = await Chats.unarchive_all_chats_by_user_id(user.id, db=db) if result: + await Tags.ensure_tags_exist(list(tag_ids), user.id, db=db) await publish_event(request, EVENTS.CHAT_UNARCHIVED, actor=user, subject_id=user.id, subject_type='user') return result