diff --git a/data_management/opensearch_indexer/opensearch_indexer/index_consignment/bulk_index_consignment.py b/data_management/opensearch_indexer/opensearch_indexer/index_consignment/bulk_index_consignment.py index 67f7a342..0f66deac 100644 --- a/data_management/opensearch_indexer/opensearch_indexer/index_consignment/bulk_index_consignment.py +++ b/data_management/opensearch_indexer/opensearch_indexer/index_consignment/bulk_index_consignment.py @@ -2,6 +2,7 @@ import logging from typing import Dict, List, Optional, Tuple, Union +import pg8000 from opensearchpy import OpenSearch, RequestsHttpConnection from requests_aws4auth import AWS4Auth from sqlalchemy import create_engine, text @@ -170,18 +171,17 @@ def _fetch_files_in_consignment( c."ConsignmentReference" = :consignment_reference AND f."FileType" = 'File'; """ - # try: - # result = session.execute( - # text(query), {"consignment_reference": consignment_reference} - # ).fetchall() - # except pg8000.Error as e: - # raise Exception(f"Database query failed: {e}") - # finally: - # session.close() - - result = session.execute( - text(query), {"consignment_reference": consignment_reference} - ).fetchall() + try: + result = session.execute( + text(query), {"consignment_reference": consignment_reference} + ).fetchall() + except pg8000.Error as e: + logger.error( + f"Failed to retrieve file metadata from database for consignment reference: {consignment_reference}" + ) + session.close() + raise e + session.close() # Process query results