From 2d7b312e6ce368e32dd453b95de2f746121a3120 Mon Sep 17 00:00:00 2001 From: rkuo-danswer Date: Thu, 5 Sep 2024 13:09:33 -0700 Subject: [PATCH] harden indexing-status endpoint against db changes happening in the background. Needs further improvement but OK for now. (#2338) --- backend/danswer/server/documents/connector.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/danswer/server/documents/connector.py b/backend/danswer/server/documents/connector.py index 52bec7d7f..34496c625 100644 --- a/backend/danswer/server/documents/connector.py +++ b/backend/danswer/server/documents/connector.py @@ -387,7 +387,12 @@ def get_connector_indexing_status( ) -> list[ConnectorIndexingStatus]: indexing_statuses: list[ConnectorIndexingStatus] = [] - # TODO: make this one query + # NOTE: If the connector is deleting behind the scenes, + # accessing cc_pairs can be inconsistent and members like + # connector or credential may be None. + # Additional checks are done to make sure the connector and credential still exists. + # TODO: make this one query ... possibly eager load or wrap in a read transaction + # to avoid the complexity of trying to error check throughout the function cc_pairs = get_connector_credential_pairs( db_session=db_session, user=user, @@ -440,6 +445,10 @@ def get_connector_indexing_status( connector = cc_pair.connector credential = cc_pair.credential + if not connector or not credential: + # This may happen if background deletion is happening + continue + latest_index_attempt = cc_pair_to_latest_index_attempt.get( (connector.id, credential.id) )