From f83e7bfcd9bb95bddeb852d445414f6727193d55 Mon Sep 17 00:00:00 2001 From: Yuhong Sun Date: Thu, 19 Dec 2024 09:43:12 -0800 Subject: [PATCH] Fix Default CC Pair (#3513) --- backend/onyx/configs/constants.py | 2 ++ backend/onyx/db/connector_credential_pair.py | 3 +++ backend/onyx/server/documents/cc_pair.py | 3 ++- backend/onyx/server/onyx_api/ingestion.py | 3 ++- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/onyx/configs/constants.py b/backend/onyx/configs/constants.py index d9e433df7..7892dafaf 100644 --- a/backend/onyx/configs/constants.py +++ b/backend/onyx/configs/constants.py @@ -36,6 +36,8 @@ DISABLED_GEN_AI_MSG = ( DEFAULT_PERSONA_ID = 0 +DEFAULT_CC_PAIR_ID = 1 + # Postgres connection constants for application_name POSTGRES_WEB_APP_NAME = "web" POSTGRES_INDEXER_APP_NAME = "indexer" diff --git a/backend/onyx/db/connector_credential_pair.py b/backend/onyx/db/connector_credential_pair.py index 46545c5ae..cc5fe0b9a 100644 --- a/backend/onyx/db/connector_credential_pair.py +++ b/backend/onyx/db/connector_credential_pair.py @@ -310,6 +310,9 @@ def associate_default_cc_pair(db_session: Session) -> None: if existing_association is not None: return + # DefaultCCPair has id 1 since it is the first CC pair created + # It is DEFAULT_CC_PAIR_ID, but can't set it explicitly because it messed with the + # auto-incrementing id association = ConnectorCredentialPair( connector_id=0, credential_id=0, diff --git a/backend/onyx/server/documents/cc_pair.py b/backend/onyx/server/documents/cc_pair.py index 49f657827..dd282e2fe 100644 --- a/backend/onyx/server/documents/cc_pair.py +++ b/backend/onyx/server/documents/cc_pair.py @@ -532,7 +532,8 @@ def associate_credential_to_connector( ) return response - except IntegrityError: + except IntegrityError as e: + logger.error(f"IntegrityError: {e}") raise HTTPException(status_code=400, detail="Name must be unique") diff --git a/backend/onyx/server/onyx_api/ingestion.py b/backend/onyx/server/onyx_api/ingestion.py index 1c606b0fc..cd3f90850 100644 --- a/backend/onyx/server/onyx_api/ingestion.py +++ b/backend/onyx/server/onyx_api/ingestion.py @@ -4,6 +4,7 @@ from fastapi import HTTPException from sqlalchemy.orm import Session from onyx.auth.users import api_key_dep +from onyx.configs.constants import DEFAULT_CC_PAIR_ID from onyx.configs.constants import DocumentSource from onyx.connectors.models import Document from onyx.connectors.models import IndexAttemptMetadata @@ -79,7 +80,7 @@ def upsert_ingestion_doc( document.source = DocumentSource.FILE cc_pair = get_connector_credential_pair_from_id( - cc_pair_id=doc_info.cc_pair_id or 0, db_session=db_session + cc_pair_id=doc_info.cc_pair_id or DEFAULT_CC_PAIR_ID, db_session=db_session ) if cc_pair is None: raise HTTPException(