Skip to content

Commit 6b8226f

Browse files
committed
add bulk insert error
1 parent b681e85 commit 6b8226f

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
mk_actions,
2929
mk_item_id,
3030
)
31+
from stac_fastapi.core.exceptions import BulkInsertError
3132
from stac_fastapi.core.extensions import filter
3233
from stac_fastapi.core.serializers import CollectionSerializer, ItemSerializer
3334
from stac_fastapi.core.utilities import MAX_LIMIT, bbox2polygon
@@ -955,16 +956,16 @@ def _handle_bulk_result(
955956
"""
956957
success_count, error_list = result
957958

958-
# if raise_errors and error_list:
959-
# error_messages = [
960-
# f"Item {e['index']['_id']}: {e['index']['error']['reason']}"
961-
# for e in error_list
962-
# ]
963-
# raise BulkInsertError(
964-
# f"Bulk operation failed with {len(error_list)} errors",
965-
# success_count=success_count,
966-
# errors=error_messages,
967-
# )
959+
if raise_errors and error_list:
960+
error_messages = [
961+
f"Item {e['index']['_id']}: {e['index']['error']['reason']}"
962+
for e in error_list
963+
]
964+
raise BulkInsertError(
965+
f"Bulk operation failed with {len(error_list)} errors",
966+
success_count=success_count,
967+
errors=error_messages,
968+
)
968969

969970
return success_count, error_list
970971

stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
mk_actions,
3232
mk_item_id,
3333
)
34+
from stac_fastapi.core.exceptions import BulkInsertError
3435
from stac_fastapi.core.extensions import filter
3536
from stac_fastapi.core.utilities import MAX_LIMIT, bbox2polygon
3637
from stac_fastapi.opensearch.config import (
@@ -986,16 +987,16 @@ def _handle_bulk_result(
986987
"""
987988
success_count, error_list = result
988989

989-
# if raise_errors and error_list:
990-
# error_messages = [
991-
# f"Item {e['index']['_id']}: {e['index']['error']['reason']}"
992-
# for e in error_list
993-
# ]
994-
# raise BulkInsertError(
995-
# f"Bulk operation completed with {len(error_list)} errors",
996-
# success_count=success_count,
997-
# errors=error_messages,
998-
# )
990+
if raise_errors and error_list:
991+
error_messages = [
992+
f"Item {e['index']['_id']}: {e['index']['error']['reason']}"
993+
for e in error_list
994+
]
995+
raise BulkInsertError(
996+
f"Bulk operation completed with {len(error_list)} errors",
997+
success_count=success_count,
998+
errors=error_messages,
999+
)
9991000

10001001
return success_count, error_list
10011002

0 commit comments

Comments
 (0)