From 70d7ca5c7354b662e87be3e0dc7ebdf25f5a5a7d Mon Sep 17 00:00:00 2001 From: Weves Date: Thu, 17 Aug 2023 14:08:24 -0700 Subject: [PATCH] Better error for missing allowed_users / allowed_groups --- backend/danswer/datastores/qdrant/indexing.py | 22 +++++++++++++++++-- backend/danswer/datastores/typesense/store.py | 22 ++++++++++++++----- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/backend/danswer/datastores/qdrant/indexing.py b/backend/danswer/datastores/qdrant/indexing.py index 5d0f445e11..2f4d45e478 100644 --- a/backend/danswer/datastores/qdrant/indexing.py +++ b/backend/danswer/datastores/qdrant/indexing.py @@ -1,5 +1,6 @@ import json from functools import partial +from typing import cast from uuid import UUID from qdrant_client import QdrantClient @@ -68,9 +69,26 @@ def get_qdrant_document_cross_connector_metadata( if len(results) == 0: return None payload = get_payload_from_record(results[0]) + allowed_users = cast(list[str] | None, payload.get(ALLOWED_USERS)) + allowed_groups = cast(list[str] | None, payload.get(ALLOWED_GROUPS)) + if allowed_users is None: + allowed_users = [] + logger.error( + "Qdrant Index is corrupted, Document found with no user access lists." + f"Assuming no users have access to chunk with ID '{doc_chunk_id}'." + ) + if allowed_groups is None: + allowed_groups = [] + logger.error( + "Qdrant Index is corrupted, Document found with no groups access lists." + f"Assuming no groups have access to chunk with ID '{doc_chunk_id}'." + ) + return CrossConnectorDocumentMetadata( - allowed_users=payload[ALLOWED_USERS], - allowed_user_groups=payload[ALLOWED_GROUPS], + # if either `allowed_users` or `allowed_groups` are missing from the + # point, then assume that the document has no allowed users. + allowed_users=allowed_users, + allowed_user_groups=allowed_groups, already_in_index=True, ) diff --git a/backend/danswer/datastores/typesense/store.py b/backend/danswer/datastores/typesense/store.py index abd87d3df1..59f657dae8 100644 --- a/backend/danswer/datastores/typesense/store.py +++ b/backend/danswer/datastores/typesense/store.py @@ -92,13 +92,25 @@ def get_typesense_document_cross_connector_metadata( ) except ObjectNotFound: return None - if document[ALLOWED_USERS] is None or document[ALLOWED_GROUPS] is None: - raise RuntimeError( - "Typesense Index is corrupted, Document found with no access lists." + + allowed_users = cast(list[str] | None, document.get(ALLOWED_USERS)) + allowed_groups = cast(list[str] | None, document.get(ALLOWED_GROUPS)) + if allowed_users is None: + allowed_users = [] + logger.error( + "Typesense Index is corrupted, Document found with no user access lists." + f"Assuming no users have access to chunk with ID '{doc_chunk_id}'." ) + if allowed_groups is None: + allowed_groups = [] + logger.error( + "Typesense Index is corrupted, Document found with no groups access lists." + f"Assuming no groups have access to chunk with ID '{doc_chunk_id}'." + ) + return CrossConnectorDocumentMetadata( - allowed_users=document[ALLOWED_USERS], - allowed_user_groups=document[ALLOWED_GROUPS], + allowed_users=allowed_users, + allowed_user_groups=allowed_groups, already_in_index=True, )