From a9e4695b741885689db60b0dbedb3c5d15d6d9c5 Mon Sep 17 00:00:00 2001 From: liwenju0 Date: Wed, 26 Feb 2025 15:47:34 +0800 Subject: [PATCH] =?UTF-8?q?Fix=EF=BC=9Avalidate=20knowledge=20base=20assoc?= =?UTF-8?q?iation=20before=20document=20upload=20(#5373)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What problem does this PR solve? fix this bug: https://github.com/infiniflow/ragflow/issues/5368 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) Co-authored-by: wenju.li --- api/db/services/document_service.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/db/services/document_service.py b/api/db/services/document_service.py index 4e94f928..4c59271e 100644 --- a/api/db/services/document_service.py +++ b/api/db/services/document_service.py @@ -504,6 +504,9 @@ def doc_upload_and_parse(conversation_id, file_objs, user_id): assert e, "Conversation not found!" e, dia = DialogService.get_by_id(conv.dialog_id) + if not dia.kb_ids: + raise LookupError("No knowledge base associated with this conversation. " + "Please add a knowledge base before uploading documents") kb_id = dia.kb_ids[0] e, kb = KnowledgebaseService.get_by_id(kb_id) if not e: