From 8a17e3d7acec3abe1d0fc18950b66ff88583964a Mon Sep 17 00:00:00 2001 From: rohanmarwaha Date: Fri, 8 Mar 2024 14:26:57 -0600 Subject: [PATCH] Fix deletion bug in retrieval_service to check for materials before deleting --- ai_ta_backend/service/retrieval_service.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ai_ta_backend/service/retrieval_service.py b/ai_ta_backend/service/retrieval_service.py index 3f13c311..3d73a82b 100644 --- a/ai_ta_backend/service/retrieval_service.py +++ b/ai_ta_backend/service/retrieval_service.py @@ -317,23 +317,22 @@ def delete_from_nomic_and_supabase(self, course_name: str, identifier_key: str, try: print(f"Deleting from Nomic and Supabase for {course_name} using {identifier_key}: {identifier_value}") response = self.sqlDb.getMaterialsForCourseAndKeyAndValue(course_name, identifier_key, identifier_value) - print(f"Trying to delete materials: {response}") + if not response.data: + raise Exception(f"No materials found for {course_name} using {identifier_key}: {identifier_value}") data = response.data[0] # single record fetched nomic_ids_to_delete = [str(data['id']) + "_" + str(i) for i in range(1, len(data['contexts']) + 1)] # delete from Nomic # check if project exists response = self.sqlDb.getProjectsMapForCourse(course_name) - if response.data: - project_id = response.data[0]['doc_map_id'] - else: - return "No document map found for this course" + if not response.data: + raise Exception(f"No document map found for this course: {course_name}") + project_id = response.data[0]['doc_map_id'] self.nomicService.delete_from_document_map(project_id, nomic_ids_to_delete) # delete from Supabase print(f"Deleting from Supabase for {course_name} using {identifier_key}: {identifier_value}") response = self.sqlDb.deleteMaterialsForCourseAndKeyAndValue(course_name, identifier_key, identifier_value) - print(f"Deleted from sql: {response}") except Exception as e: print(f"Error in deleting file from Nomic or Supabase using {identifier_key}: {identifier_value}", e) self.sentry.capture_exception(e)