Skip to content

Update stac-fastapi to v2.4.8 #151

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 5 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions stac_fastapi/elasticsearch/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
install_requires = [
"fastapi",
"attrs",
"pydantic[dotenv]",
"pydantic[dotenv]<2",
"stac_pydantic==2.0.*",
"stac-fastapi.types==2.4.3",
"stac-fastapi.api==2.4.3",
"stac-fastapi.extensions==2.4.3",
"stac-fastapi.types==2.4.8",
"stac-fastapi.api==2.4.8",
"stac-fastapi.extensions==2.4.8",
"elasticsearch[async]==7.17.9",
"elasticsearch-dsl==7.4.1",
"pystac[validation]",
Expand Down
47 changes: 3 additions & 44 deletions stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
"""FastAPI application."""
from typing import List

import attr

from stac_fastapi.api.app import StacApi
from stac_fastapi.api.models import create_get_request_model, create_post_request_model
from stac_fastapi.elasticsearch.config import ElasticsearchSettings
Expand All @@ -28,52 +24,15 @@
settings = ElasticsearchSettings()
session = Session.create_from_settings(settings)


@attr.s
class FixedSortExtension(SortExtension):
"""SortExtension class fixed with correct paths, removing extra forward-slash."""

conformance_classes: List[str] = attr.ib(
factory=lambda: ["https://api.stacspec.org/v1.0.0-beta.4/item-search#sort"]
)


@attr.s
class FixedFilterExtension(FilterExtension):
"""FilterExtension class fixed with correct paths, removing extra forward-slash."""

conformance_classes: List[str] = attr.ib(
default=[
"https://api.stacspec.org/v1.0.0-rc.1/item-search#filter",
"http://www.opengis.net/spec/ogcapi-features-3/1.0/conf/filter",
"http://www.opengis.net/spec/ogcapi-features-3/1.0/conf/features-filter",
"http://www.opengis.net/spec/cql2/1.0/conf/cql2-text",
"http://www.opengis.net/spec/cql2/1.0/conf/cql2-json",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to fix this upstream and then intersect with the the fix in the next release, rather than keep all of this override code just to advertise correctly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you use cql2-json in this project and it maybe isn't used in the other stac-fastapi versions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, pgstac supports both also. I think it was just an oversight when the conformance classes were refactored.

In fact, pgstac's primary support is for CQL2 JSON, and the CQL Text inputs are first translated to JSON before being passed to the backend.

"http://www.opengis.net/spec/cql2/1.0/conf/basic-cql2",
"http://www.opengis.net/spec/cql2/1.0/conf/basic-spatial-operators",
]
)
client = attr.ib(factory=EsAsyncBaseFiltersClient)


@attr.s
class FixedQueryExtension(QueryExtension):
"""Fixed Query Extension string."""

conformance_classes: List[str] = attr.ib(
factory=lambda: ["https://api.stacspec.org/v1.0.0-beta.4/item-search#query"]
)


extensions = [
TransactionExtension(client=TransactionsClient(session=session), settings=settings),
BulkTransactionExtension(client=BulkTransactionsClient(session=session)),
FieldsExtension(),
FixedQueryExtension(),
FixedSortExtension(),
QueryExtension(),
SortExtension(),
TokenPaginationExtension(),
ContextExtension(),
FixedFilterExtension(),
FilterExtension(client=EsAsyncBaseFiltersClient()),
]

post_request_model = create_post_request_model(extensions)
Expand Down
5 changes: 5 additions & 0 deletions stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ async def get_search(
token: Optional[str] = None,
fields: Optional[List[str]] = None,
sortby: Optional[str] = None,
intersects: Optional[str] = None,
# filter: Optional[str] = None, # todo: requires fastapi > 2.3 unreleased
# filter_lang: Optional[str] = None, # todo: requires fastapi > 2.3 unreleased
**kwargs,
Expand All @@ -302,6 +303,7 @@ async def get_search(
token (Optional[str]): Access token to use when searching the catalog.
fields (Optional[List[str]]): Fields to include or exclude from the results.
sortby (Optional[str]): Sorting options for the results.
intersects (Optional[str]): GeoJSON geometry to search in.
kwargs: Additional parameters to be passed to the API.

Returns:
Expand All @@ -322,6 +324,9 @@ async def get_search(
if datetime:
base_args["datetime"] = datetime

if intersects:
base_args["intersects"] = intersects

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know we don't support intersection for GET /search. I'm not sure what an intersection query looks like in a GET request? We probably need to do something to support it. This is in the sqlalchemy implementation - https://github.com/stac-utils/stac-fastapi-sqlalchemy/blob/b09564cf78773748b13a95a9751c23270c7aa718/stac_fastapi/sqlalchemy/core.py#L271-L272

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bug if it's not supported. The GET intersects parameter format is just a stringified GeoJSON geometry.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you show me what this looks like? Wouldn't we have to convert the string to geojson?

Copy link
Collaborator

@jonhealy1 jonhealy1 Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We at least need a test to prove that it works.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the string might need to be converted to a dict[str,Any] -- I'd have to look at what type base_args is expecting for intersects.

if sortby:
# https://github.com/radiantearth/stac-spec/tree/master/api-spec/extensions/sort#http-get-or-post-form
sort_param = []
Expand Down
4 changes: 3 additions & 1 deletion stac_fastapi/elasticsearch/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ async def test_app_query_extension_limit_lt0(app_client):


async def test_app_query_extension_limit_gt10000(app_client):
assert (await app_client.post("/search", json={"limit": 10001})).status_code == 400
resp = await app_client.post("/search", json={"limit": 10001})
assert resp.status_code == 200
assert resp.json()["context"]["limit"] == 10000


async def test_app_query_extension_limit_10000(app_client):
Expand Down
14 changes: 6 additions & 8 deletions stac_fastapi/elasticsearch/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@

from stac_fastapi.api.app import StacApi
from stac_fastapi.api.models import create_get_request_model, create_post_request_model
from stac_fastapi.elasticsearch.app import (
FixedFilterExtension,
FixedQueryExtension,
FixedSortExtension,
)
from stac_fastapi.elasticsearch.config import AsyncElasticsearchSettings
from stac_fastapi.elasticsearch.core import (
BulkTransactionsClient,
CoreClient,
TransactionsClient,
)
from stac_fastapi.elasticsearch.database_logic import create_collection_index
from stac_fastapi.elasticsearch.extensions import QueryExtension
from stac_fastapi.extensions.core import ( # FieldsExtension,
ContextExtension,
FieldsExtension,
FilterExtension,
SortExtension,
TokenPaginationExtension,
TransactionExtension,
)
Expand Down Expand Up @@ -160,11 +158,11 @@ async def app():
client=TransactionsClient(session=None), settings=settings
),
ContextExtension(),
FixedSortExtension(),
SortExtension(),
FieldsExtension(),
FixedQueryExtension(),
QueryExtension(),
TokenPaginationExtension(),
FixedFilterExtension(),
FilterExtension(),
]

post_request_model = create_post_request_model(extensions)
Expand Down