From 49c125ab0e2dab4dcd9b13649349669b3c7f8e3f Mon Sep 17 00:00:00 2001 From: "Richard Kuo (Danswer)" Date: Tue, 10 Dec 2024 11:41:37 -0800 Subject: [PATCH] don't delete index attempts, just update them --- backend/danswer/db/index_attempt.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/backend/danswer/db/index_attempt.py b/backend/danswer/db/index_attempt.py index 06bbee10559..2c8ccd99aa0 100644 --- a/backend/danswer/db/index_attempt.py +++ b/backend/danswer/db/index_attempt.py @@ -522,12 +522,16 @@ def expire_index_attempts( search_settings_id: int, db_session: Session, ) -> None: - delete_query = ( - delete(IndexAttempt) + not_started_query = ( + update(IndexAttempt) .where(IndexAttempt.search_settings_id == search_settings_id) .where(IndexAttempt.status == IndexingStatus.NOT_STARTED) + .values( + status=IndexingStatus.CANCELED, + error_msg="Canceled, likely due to model swap", + ) ) - db_session.execute(delete_query) + db_session.execute(not_started_query) update_query = ( update(IndexAttempt) @@ -549,9 +553,14 @@ def cancel_indexing_attempts_for_ccpair( include_secondary_index: bool = False, ) -> None: stmt = ( - delete(IndexAttempt) + update(IndexAttempt) .where(IndexAttempt.connector_credential_pair_id == cc_pair_id) .where(IndexAttempt.status == IndexingStatus.NOT_STARTED) + .values( + status=IndexingStatus.CANCELED, + error_msg="Canceled by user", + time_started=datetime.now(timezone.utc), + ) ) if not include_secondary_index: