Skip to content

Commit 00c34ad

Browse files
committed
Use logger.warning instead of ValueError for too many unique values in enum
1 parent 636e988 commit 00c34ad

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
from typing import Any, Dict, Iterable, List, Optional, Tuple, Type, Union
99

1010
import attr
11+
from starlette.requests import Request
12+
1113
import elasticsearch.helpers as helpers
1214
from elasticsearch.dsl import Q, Search
1315
from elasticsearch.exceptions import NotFoundError as ESNotFoundError
14-
from starlette.requests import Request
15-
1616
from stac_fastapi.core.base_database_logic import BaseDatabaseLogic
1717
from stac_fastapi.core.serializers import CollectionSerializer, ItemSerializer
1818
from stac_fastapi.core.utilities import MAX_LIMIT, bbox2polygon
@@ -916,7 +916,13 @@ async def get_items_unique_values(
916916
result: Dict[str, List[str]] = {}
917917
for field, agg in query["aggregations"].items():
918918
if len(agg["buckets"]) > limit:
919-
raise ValueError(f"Field {field} has more than {limit} unique values.")
919+
logger.warning(
920+
"Skipping enum field %s: exceeds limit of %d unique values. "
921+
"Consider excluding this field from enumeration or increase the limit.",
922+
field,
923+
limit,
924+
)
925+
continue
920926
result[field] = [bucket["key"] for bucket in agg["buckets"]]
921927
return result
922928

stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,13 @@ async def get_items_unique_values(
925925
result: Dict[str, List[str]] = {}
926926
for field, agg in query["aggregations"].items():
927927
if len(agg["buckets"]) > limit:
928-
raise ValueError(f"Field {field} has more than {limit} unique values.")
928+
logger.warning(
929+
"Skipping enum field %s: exceeds limit of %d unique values. "
930+
"Consider excluding this field from enumeration or increase the limit.",
931+
field,
932+
limit,
933+
)
934+
continue
929935
result[field] = [bucket["key"] for bucket in agg["buckets"]]
930936
return result
931937

0 commit comments

Comments
 (0)