Skip to content

Commit

Permalink
Fix deletion bug in retrieval_service to check for materials before d…
Browse files Browse the repository at this point in the history
…eleting
  • Loading branch information
rohan-uiuc committed Mar 8, 2024
1 parent f5a36fc commit 8a17e3d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions ai_ta_backend/service/retrieval_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8a17e3d

Please sign in to comment.