From ddd28a234aab536f8a4614cda0d47dc29fdcc382 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Tue, 4 Aug 2026 18:02:55 +0200 Subject: [PATCH] refac: keep external connections until their last knowledge base is removed Deleting an external knowledge base now clears its connection only when an admin removes the last knowledge base referencing it, matching the connection delete route. --- backend/open_webui/routers/knowledge.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/routers/knowledge.py b/backend/open_webui/routers/knowledge.py index 625095e872..942fea3316 100644 --- a/backend/open_webui/routers/knowledge.py +++ b/backend/open_webui/routers/knowledge.py @@ -1721,7 +1721,12 @@ async def delete_knowledge_by_id( # Clean up vector DB if is_external_knowledge(knowledge): connection_id = (knowledge.meta or {}).get('external', {}).get('connection_id') - if connection_id: + # Connections are admin-owned and shared across knowledge bases + if ( + connection_id + and user.role == 'admin' + and await _count_external_connection_mappings(connection_id, db=db) <= 1 + ): connections = [ connection for connection in await _get_external_connections() if connection.get('id') != connection_id ]