Skip to content

Commit 1e7346f

Browse files
committed
more type fixes
1 parent f4e9c3f commit 1e7346f

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

stac_fastapi/core/stac_fastapi/core/core.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ async def item_collection(
334334
search=search,
335335
limit=limit,
336336
sort=None,
337-
token=token, # type: ignore
337+
token=token,
338338
collection_ids=[collection_id],
339339
)
340340

@@ -633,7 +633,7 @@ async def post_search(
633633
items, maybe_count, next_token = await self.database.execute_search(
634634
search=search,
635635
limit=limit,
636-
token=search_request.token, # type: ignore
636+
token=search_request.token,
637637
sort=sort,
638638
collection_ids=search_request.collections,
639639
)
@@ -701,7 +701,10 @@ async def create_item(
701701
database=self.database, settings=self.settings
702702
)
703703
processed_items = [
704-
bulk_client.preprocess_item(item, base_url, BulkTransactionMethod.INSERT) for item in item["features"] # type: ignore
704+
bulk_client.preprocess_item(
705+
item, base_url, BulkTransactionMethod.INSERT
706+
)
707+
for item in item["features"]
705708
]
706709

707710
await self.database.bulk_async(

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
from typing import Any, Dict, Set
77

88
import certifi
9+
from elasticsearch._async.client import AsyncElasticsearch
910

10-
from elasticsearch import AsyncElasticsearch, Elasticsearch # type: ignore
11+
from elasticsearch import Elasticsearch # type: ignore[attr-defined]
1112
from stac_fastapi.core.base_settings import ApiBaseSettings
1213
from stac_fastapi.core.utilities import get_bool_env
1314
from stac_fastapi.types.config import ApiSettings

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

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

1010
import attr
11+
import elasticsearch.helpers as helpers
1112
from elasticsearch.dsl import Q, Search
13+
from elasticsearch.exceptions import NotFoundError as ESNotFoundError
1214
from starlette.requests import Request
1315

14-
from elasticsearch import exceptions, helpers # type: ignore
1516
from stac_fastapi.core.base_database_logic import BaseDatabaseLogic
1617
from stac_fastapi.core.database_logic import (
1718
COLLECTIONS_INDEX,
@@ -271,7 +272,7 @@ async def get_one_item(self, collection_id: str, item_id: str) -> Dict:
271272
index=index_alias_by_collection_id(collection_id),
272273
id=mk_item_id(item_id, collection_id),
273274
)
274-
except exceptions.NotFoundError:
275+
except ESNotFoundError:
275276
raise NotFoundError(
276277
f"Item {item_id} does not exist inside Collection {collection_id}"
277278
)
@@ -511,7 +512,7 @@ async def execute_search(
511512

512513
try:
513514
es_response = await search_task
514-
except exceptions.NotFoundError:
515+
except ESNotFoundError:
515516
raise NotFoundError(f"Collections '{collection_ids}' do not exist")
516517

517518
hits = es_response["hits"]["hits"]
@@ -594,7 +595,7 @@ def _fill_aggregation_parameters(name: str, agg: dict) -> dict:
594595

595596
try:
596597
db_response = await search_task
597-
except exceptions.NotFoundError:
598+
except ESNotFoundError:
598599
raise NotFoundError(f"Collections '{collection_ids}' do not exist")
599600

600601
return db_response
@@ -720,7 +721,7 @@ async def delete_item(
720721
id=mk_item_id(item_id, collection_id),
721722
refresh=refresh,
722723
)
723-
except exceptions.NotFoundError:
724+
except ESNotFoundError:
724725
raise NotFoundError(
725726
f"Item {item_id} in collection {collection_id} not found"
726727
)
@@ -740,7 +741,7 @@ async def get_items_mapping(self, collection_id: str) -> Dict[str, Any]:
740741
index=index_name, allow_no_indices=False
741742
)
742743
return mapping.body
743-
except exceptions.NotFoundError:
744+
except ESNotFoundError:
744745
raise NotFoundError(f"Mapping for index {index_name} not found")
745746

746747
async def create_collection(self, collection: Collection, refresh: bool = False):
@@ -791,7 +792,7 @@ async def find_collection(self, collection_id: str) -> Collection:
791792
collection = await self.client.get(
792793
index=COLLECTIONS_INDEX, id=collection_id
793794
)
794-
except exceptions.NotFoundError:
795+
except ESNotFoundError:
795796
raise NotFoundError(f"Collection {collection_id} not found")
796797

797798
return collection["_source"]

0 commit comments

Comments
 (0)