Skip to content

Commit 2d49243

Browse files
YuriZmytrakovYuri Zmytrakov
andauthored
fix: ensure datetime in post request is normalized (#543)
**Description:** Currently, in `POST` requests to `/search`, with datetime values are not normalized as they are in `GET` requests to `/search`, which can cause different results to be returned for the same datetime filter. For example: `POST` request to `/search` with `datetime=2025-11-20T09:54:38Z/2025-11-20T09:54:38Z` returns an item with `2025-11-20T09:54:38.196614Z`, whereas a GET request with the same datetime filter does not which is expected behavior. This PR ensures that datetime values in `POST` requests are normalized in the same way as in `GET` requests. **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [ ] Documentation has been updated to reflect changes, if applicable - [x] Changes are added to the changelog --------- Co-authored-by: Yuri Zmytrakov <yzmytrakovNB@yzmytrakovNB.local>
1 parent 6f74a12 commit 2d49243

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1414
### Fixed
1515

1616
- Fixed datetime filtering for .0Z milliseconds to preserve precision in apply_filter_datetime, ensuring only items exactly within the specified range are returned. [#535](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/535)
17+
- Normalize datetime in POST /search requests to match GET /search behavior. [#543](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/543)
1718

1819
### Removed
1920

stac_fastapi/core/stac_fastapi/core/core.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,10 @@ async def post_search(
790790
search=search, collection_ids=search_request.collections
791791
)
792792

793+
datetime_parsed = format_datetime_range(date_str=search_request.datetime)
793794
try:
794795
search, datetime_search = self.database.apply_datetime_filter(
795-
search=search, datetime=search_request.datetime
796+
search=search, datetime=datetime_parsed
796797
)
797798
except (ValueError, TypeError) as e:
798799
# Handle invalid interval formats if return_date fails

0 commit comments

Comments
 (0)