Skip to content

Inherit from Base Database Logic #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/deploy_mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
- name: Checkout main
uses: actions/checkout@v4

- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.9

- name: Install dependencies
run: |
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

### Changed

### Fixed

## [v4.0.0a0]

### Added
Expand All @@ -22,6 +28,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed
- Improved performance of `mk_actions` and `filter-links` methods [#351](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/351)
- Fixed inheritance relating to BaseDatabaseSettings and ApiBaseSettings [#355](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/355)
- Fixed delete_item and delete_collection methods return types [#355](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/355)
- Fixed inheritance relating to DatabaseLogic and BaseDatabaseLogic, and ApiBaseSettings [#355](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/355)

## [v3.2.5] - 2025-04-07

Expand Down
17 changes: 6 additions & 11 deletions stac_fastapi/core/stac_fastapi/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,17 +745,15 @@ async def update_item(
return ItemSerializer.db_to_stac(item, base_url)

@overrides
async def delete_item(
self, item_id: str, collection_id: str, **kwargs
) -> Optional[stac_types.Item]:
async def delete_item(self, item_id: str, collection_id: str, **kwargs) -> None:
"""Delete an item from a collection.

Args:
item_id (str): The identifier of the item to delete.
collection_id (str): The identifier of the collection that contains the item.

Returns:
Optional[stac_types.Item]: The deleted item, or `None` if the item was successfully deleted.
None: Returns 204 No Content on successful deletion
"""
await self.database.delete_item(item_id=item_id, collection_id=collection_id)
return None
Expand Down Expand Up @@ -825,23 +823,20 @@ async def update_collection(
)

@overrides
async def delete_collection(
self, collection_id: str, **kwargs
) -> Optional[stac_types.Collection]:
async def delete_collection(self, collection_id: str, **kwargs) -> None:
"""
Delete a collection.

This method deletes an existing collection in the database.

Args:
collection_id (str): The identifier of the collection that contains the item.
kwargs: Additional keyword arguments.
collection_id (str): The identifier of the collection to delete

Returns:
None.
None: Returns 204 No Content on successful deletion

Raises:
NotFoundError: If the collection doesn't exist.
NotFoundError: If the collection doesn't exist
"""
await self.database.delete_collection(collection_id=collection_id)
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import certifi

from elasticsearch import AsyncElasticsearch, Elasticsearch # type: ignore
from stac_fastapi.core.base_settings import ApiBaseSettings
from stac_fastapi.types.config import ApiSettings


Expand Down Expand Up @@ -69,7 +70,7 @@ def _es_config() -> Dict[str, Any]:
_forbidden_fields: Set[str] = {"type"}


class ElasticsearchSettings(ApiSettings):
class ElasticsearchSettings(ApiSettings, ApiBaseSettings):
"""API settings."""

# Fields which are defined by STAC but not included in the database model
Expand All @@ -82,7 +83,7 @@ def create_client(self):
return Elasticsearch(**_es_config())


class AsyncElasticsearchSettings(ApiSettings):
class AsyncElasticsearchSettings(ApiSettings, ApiBaseSettings):
"""API settings."""

# Fields which are defined by STAC but not included in the database model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from starlette.requests import Request

from elasticsearch import exceptions, helpers # type: ignore
from stac_fastapi.core.base_database_logic import BaseDatabaseLogic
from stac_fastapi.core.database_logic import (
COLLECTIONS_INDEX,
DEFAULT_SORT,
Expand Down Expand Up @@ -124,7 +125,7 @@ async def delete_item_index(collection_id: str):


@attr.s
class DatabaseLogic:
class DatabaseLogic(BaseDatabaseLogic):
"""Database logic."""

client = AsyncElasticsearchSettings().create_client
Expand Down
5 changes: 3 additions & 2 deletions stac_fastapi/opensearch/stac_fastapi/opensearch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import certifi
from opensearchpy import AsyncOpenSearch, OpenSearch

from stac_fastapi.core.base_settings import ApiBaseSettings
from stac_fastapi.types.config import ApiSettings


Expand Down Expand Up @@ -67,7 +68,7 @@ def _es_config() -> Dict[str, Any]:
_forbidden_fields: Set[str] = {"type"}


class OpensearchSettings(ApiSettings):
class OpensearchSettings(ApiSettings, ApiBaseSettings):
"""API settings."""

# Fields which are defined by STAC but not included in the database model
Expand All @@ -80,7 +81,7 @@ def create_client(self):
return OpenSearch(**_es_config())


class AsyncOpensearchSettings(ApiSettings):
class AsyncOpensearchSettings(ApiSettings, ApiBaseSettings):
"""API settings."""

# Fields which are defined by STAC but not included in the database model
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from starlette.requests import Request

from stac_fastapi.core import serializers
from stac_fastapi.core.base_database_logic import BaseDatabaseLogic
from stac_fastapi.core.database_logic import (
COLLECTIONS_INDEX,
DEFAULT_SORT,
Expand Down Expand Up @@ -145,7 +146,7 @@ async def delete_item_index(collection_id: str):


@attr.s
class DatabaseLogic:
class DatabaseLogic(BaseDatabaseLogic):
"""Database logic."""

client = AsyncSearchSettings().create_client
Expand Down