diff --git a/backend/open_webui/apps/webui/models/chats.py b/backend/open_webui/apps/webui/models/chats.py index 9032d2e35..15501e49a 100644 --- a/backend/open_webui/apps/webui/models/chats.py +++ b/backend/open_webui/apps/webui/models/chats.py @@ -561,7 +561,7 @@ class ChatTable: if tag_id not in chat.meta.get("tags", []): chat.meta = { **chat.meta, - "tags": chat.meta.get("tags", []) + [tag_id], + "tags": list(set(chat.meta.get("tags", []) + [tag_id])), } db.commit() @@ -618,7 +618,7 @@ class ChatTable: tags = [tag for tag in tags if tag != tag_id] chat.meta = { **chat.meta, - "tags": tags, + "tags": list(set(tags)), } db.commit() return True diff --git a/backend/open_webui/migrations/versions/1af9b942657b_migrate_tags.py b/backend/open_webui/migrations/versions/1af9b942657b_migrate_tags.py index 9d79b5749..8a0ab1b49 100644 --- a/backend/open_webui/migrations/versions/1af9b942657b_migrate_tags.py +++ b/backend/open_webui/migrations/versions/1af9b942657b_migrate_tags.py @@ -135,7 +135,7 @@ def upgrade(): tags = chat_updates[chat_id]["meta"].get("tags", []) tags.append(tag_name) - chat_updates[chat_id]["meta"]["tags"] = tags + chat_updates[chat_id]["meta"]["tags"] = list(set(tags)) # Update chats based on accumulated changes for chat_id, updates in chat_updates.items():