-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* prepare for 4.0 * Bump version: 3.0.5 → 4.0.0 * Update docs/src/migrations/v4.0.0.md Co-authored-by: Pete Gadomski <[email protected]> --------- Co-authored-by: Pete Gadomski <[email protected]>
- Loading branch information
1 parent
2a72400
commit 5ded0c6
Showing
13 changed files
with
208 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.0.5 | ||
4.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
# stac-fastapi v4.0 Migration Guide | ||
|
||
This document aims to help you update your application from **stac-fastapi** 3.0 to 4.0 | ||
|
||
## CHANGELOG | ||
### Changed | ||
|
||
* use `string` type instead of python `datetime.datetime` for datetime parameter in `BaseSearchGetRequest`, `ItemCollectionUri` and `BaseCollectionSearchGetRequest` GET models | ||
* rename `filter` to `filter_expr` for `FilterExtensionGetRequest` and `FilterExtensionPostRequest` attributes to avoid conflict with python filter method | ||
* remove `post_request_model` attribute in `BaseCoreClient` and `AsyncBaseCoreClient` | ||
* remove `python3.8` support | ||
|
||
### Fixed | ||
|
||
* Support multiple proxy servers in the `forwarded` header in `ProxyHeaderMiddleware` ([#782](https://github.com/stac-utils/stac-fastapi/pull/782)) | ||
|
||
## Datetime type in GET request models | ||
|
||
While the POST request models are created using stac-pydantic, the GET request models are python `attrs` classes (~dataclasses). | ||
In 4.0, we've decided to change how the `datetime` attribute was defined in `BaseSearchGetRequest`, `ItemCollectionUri` and `BaseCollectionSearchGetRequest` models to match | ||
the `datetime` definition/validation done by the pydantic model. This mostly mean that the datetime attribute forwarded to the GET endpoints will now be of type string (forwarded from the user input). | ||
|
||
```python | ||
from starlette.testclient import TestClient | ||
from stac_fastapi.api.app import StacApi | ||
from stac_fastapi.types.config import ApiSettings | ||
from stac_fastapi.types.core import BaseCoreClient | ||
|
||
class DummyCoreClient(BaseCoreClient): | ||
def all_collections(self, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
def get_collection(self, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
def get_item(self, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
def get_search(self, *args, datetime = None, **kwargs): | ||
# Return True if datetime is a string | ||
return isinstance(datetime, str) | ||
|
||
def post_search(self, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
def item_collection(self, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
api = StacApi( | ||
settings=ApiSettings(enable_response_models=False), | ||
client=DummyCoreClient(), | ||
extensions=[], | ||
) | ||
|
||
|
||
# before | ||
with TestClient(api.app) as client: | ||
response = client.get( | ||
"/search", | ||
params={ | ||
"datetime": "2020-01-01T00:00:00.00001Z", | ||
}, | ||
) | ||
assert response.json() == False | ||
|
||
# now | ||
with TestClient(api.app) as client: | ||
response = client.get( | ||
"/search", | ||
params={ | ||
"datetime": "2020-01-01T00:00:00.00001Z", | ||
}, | ||
) | ||
assert response.json() == True | ||
``` | ||
|
||
#### Start/End dates | ||
|
||
Following stac-pydantic's `Search` model, we've added class attributes to easily retrieve the `parsed` dates: | ||
|
||
```python | ||
from stac_fastapi.types.search import BaseSearchGetRequest | ||
|
||
# Interval | ||
search = BaseSearchGetRequest(datetime="2020-01-01T00:00:00.00001Z/2020-01-02T00:00:00.00001Z") | ||
|
||
search.parse_datetime() | ||
>>> (datetime.datetime(2020, 1, 1, 0, 0, 0, 10, tzinfo=datetime.timezone.utc), datetime.datetime(2020, 1, 2, 0, 0, 0, 10, tzinfo=datetime.timezone.utc)) | ||
|
||
search.start_date | ||
>>> datetime.datetime(2020, 1, 1, 0, 0, 0, 10, tzinfo=datetime.timezone.utc) | ||
|
||
search.end_date | ||
>>> datetime.datetime(2020, 1, 2, 0, 0, 0, 10, tzinfo=datetime.timezone.utc) | ||
|
||
# Single date | ||
search = BaseSearchGetRequest(datetime="2020-01-01T00:00:00.00001Z") | ||
|
||
search.parse_datetime() | ||
>>> datetime.datetime(2020, 1, 1, 0, 0, 0, 10, tzinfo=datetime.timezone.utc) | ||
|
||
search.start_date | ||
>>> datetime.datetime(2020, 1, 1, 0, 0, 0, 10, tzinfo=datetime.timezone.utc) | ||
|
||
search.end_date | ||
>>> None | ||
``` | ||
|
||
## Filter extension | ||
|
||
We've renamed the `filter` attribute to `filter_expr` in the `FilterExtensionGetRequest` and `FilterExtensionPostRequest` models to avoid any conflict with python `filter` method. This change means GET endpoints with the filter extension enabled will receive `filter_expr=` option instead of `filter=`. Same for POST endpoints where the `body` will now have a `.filter_expr` instead of a `filter` attribute. | ||
|
||
Note: This change does not affect the `input` because we use `aliases`. | ||
|
||
```python | ||
from starlette.testclient import TestClient | ||
from stac_fastapi.api.app import StacApi | ||
from stac_fastapi.api.models import create_get_request_model, create_post_request_model | ||
from stac_fastapi.extensions.core import FilterExtension | ||
from stac_fastapi.types.config import ApiSettings | ||
from stac_fastapi.types.core import BaseCoreClient | ||
|
||
class DummyCoreClient(BaseCoreClient): | ||
def all_collections(self, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
def get_collection(self, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
def get_item(self, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
def get_search(self, *args, **kwargs): | ||
return kwargs | ||
|
||
def post_search(self, *args, **kwargs): | ||
return args[0].model_dump() | ||
|
||
def item_collection(self, *args, **kwargs): | ||
raise NotImplementedError | ||
|
||
extensions = [FilterExtension()] | ||
api = StacApi( | ||
settings=ApiSettings(enable_response_models=False), | ||
client=DummyCoreClient(), | ||
extensions=extensions, | ||
search_get_request_model=create_get_request_model(extensions), | ||
search_post_request_model=create_post_request_model(extensions), | ||
) | ||
|
||
|
||
# before | ||
with TestClient(api.app) as client: | ||
response = client.post( | ||
"/search", | ||
json={ | ||
"filter": {"op": "=", "args": [{"property": "test_property"}, "test-value"]}, | ||
}, | ||
) | ||
assert response.json()["filter"] | ||
|
||
response = client.get( | ||
"/search", | ||
params={ | ||
"filter": "id='item_id' AND collection='collection_id'", | ||
}, | ||
) | ||
assert response.json()["filter"] | ||
|
||
# now | ||
with TestClient(api.app) as client: | ||
response = client.post( | ||
"/search", | ||
json={ | ||
"filter": {"op": "=", "args": [{"property": "test_property"}, "test-value"]}, | ||
}, | ||
) | ||
assert response.json()["filter_expr"] | ||
|
||
response = client.get( | ||
"/search", | ||
params={ | ||
"filter": "id='item_id' AND collection='collection_id'", | ||
}, | ||
) | ||
assert response.json()["filter_expr"] | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Library version.""" | ||
|
||
__version__ = "3.0.5" | ||
__version__ = "4.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Library version.""" | ||
|
||
__version__ = "3.0.5" | ||
__version__ = "4.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Library version.""" | ||
|
||
__version__ = "3.0.5" | ||
__version__ = "4.0.0" |