Skip to content

Update stac-fastapi parent libraries to 5.1.1 #354

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 22 commits into from
Apr 16, 2025
Merged

Conversation

jonhealy1
Copy link
Collaborator

@jonhealy1 jonhealy1 commented Apr 12, 2025

Related Issue(s):

Description:

PR Checklist:

  • Code is formatted and linted (run pre-commit run --all-files)
  • Tests pass (run make test)
  • Documentation has been updated to reflect changes, if applicable
  • Changes are added to the changelog

@jonhealy1 jonhealy1 marked this pull request as draft April 12, 2025 12:30
@jonhealy1 jonhealy1 changed the title Update stac-fastapi parent libraries to 5.1.0 Update stac-fastapi parent libraries to 5.1.1 Apr 14, 2025
@jonhealy1 jonhealy1 marked this pull request as ready for review April 14, 2025 11:18
@jonhealy1 jonhealy1 requested a review from rhysrevans3 April 15, 2025 11:07
Comment on lines 429 to 442
def _format_datetime_range(self, date_str: str) -> str:
"""
Convert a tuple of datetime objects or None into a formatted string for API requests.
Convert a datetime range into a formatted string.

Args:
date_tuple (tuple): A tuple containing two elements, each can be a datetime object or None.
date_tuple (str): A string containing two datetime values separated by a '/'.

Returns:
str: A string formatted as 'YYYY-MM-DDTHH:MM:SS.sssZ/YYYY-MM-DDTHH:MM:SS.sssZ', with '..' used if any element is None.
"""

def format_datetime(dt):
"""Format a single datetime object to the ISO8601 extended format with 'Z'."""
return dt.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z" if dt else ".."

start, end = date_tuple
return f"{format_datetime(start)}/{format_datetime(end)}"
start, end = date_str.split("/")
start = start.replace("+01:00", "Z") if start else ".."
end = end.replace("+01:00", "Z") if end else ".."
return f"{start}/{end}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this change caused by a change to stac-fastapi? I don't think we want to replace +01:00 explicitly as it could be a different timezone. Something like this would work

from datetime import datetime, timezone
start = datetime.strptime(start, "%Y-%m-%dT%H:%M:%S%z").astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ')

There's also some code in stac-fastapi that could help https://github.com/stac-utils/stac-fastapi/blob/main/stac_fastapi/types/stac_fastapi/types/rfc3339.py

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice catch here. This is a change from stac-fastapi where the get search method now accepts a string as input instead of a tuple. Let me know what you think of the new change. I was having troubles going from string to datetime object back to string and then I was wondering if it's worth it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The changes look good! One question though if a user searches for a datetime that includes a timezone like 2001-01-01T01:01:01+01:00 should the search actually be on 2001-01-01T00:01:01Z or maybe add one hour? Or is it okay just to strip that off?

If it does changes the search I think it's better to let datetime handle the timezones. We could use rfc3339_str_to_datetime from stac-fastapi to handle the string to datetime conversion. As the Item search spec states that datetimes should be formatted to that standard.

from stac_fastapi.types.rfc3339 import rfc3339_str_to_datetime
from datetime import timezone

start  = start if start == '..' else rfc3339_str_to_datetime(start).astimezone(timezone.utc).strftime('%Y-%m-%dT%H:%M:%SZ') 

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi. I have updated the code. I also had to update a test - let me know if it looks ok. Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Look great!

Comment on lines -481 to -487
tzinfo = timezone(timedelta(hours=1))
test_item = load_test_data("test_item.json")
item_date = rfc3339_str_to_datetime(test_item["properties"]["datetime"])
item_date_before = item_date - timedelta(seconds=1)
item_date_before = item_date_before.replace(tzinfo=tzinfo)
item_date_after = item_date + timedelta(seconds=1)
item_date_after = item_date_after.replace(tzinfo=tzinfo)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we wanted to keep the timezone info in the test we could use astimezone instead of replace. But I think it's okay to leave it out.

    tzinfo = timezone(timedelta(hours=1))
    test_item = load_test_data("test_item.json")
    item_date = rfc3339_str_to_datetime(test_item["properties"]["datetime"])
    item_date_before = item_date - timedelta(seconds=1)
    item_date_before = item_date_before.astimezone(tzinfo=tzinfo)
    item_date_after = item_date + timedelta(seconds=1)
    item_date_after = item_date_after.astimezone(tzinfo=tzinfo)

astimezone updates the time and timezone, replace just changes the timezone.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am getting errors in the test. Maybe we should add an issue for more comprehensive tests related to datetime parsing which is something I don't know too well.

@jonhealy1 jonhealy1 merged commit fe37609 into main Apr 16, 2025
15 checks passed
@jonhealy1 jonhealy1 deleted the stac-fastapi-v5 branch April 16, 2025 15:09
@jonhealy1 jonhealy1 mentioned this pull request Apr 24, 2025
4 tasks
jonhealy1 added a commit that referenced this pull request Apr 24, 2025
**Description:**

**Changes from 3.2.5:**

#### Added
- Added support for dynamically-generated queryables based on
Elasticsearch/OpenSearch mappings, with extensible metadata augmentation
[#351](#351)
- Included default queryables configuration for seamless integration.
[#351](#351)
- Added support for high-performance direct response mode for both
Elasticsearch and Opensearch backends, controlled by the
`ENABLE_DIRECT_RESPONSE` environment variable. When enabled
(`ENABLE_DIRECT_RESPONSE=true`), endpoints return Starlette Response
objects directly, bypassing FastAPI's jsonable_encoder and Pydantic
serialization for significantly improved performance on large search
responses. **Note:** In this mode, all FastAPI dependencies (including
authentication, custom status codes, and validation) are disabled for
all routes. Default is `false` for safety. A warning is logged at
startup if enabled. See [issue
#347](#347)
and [PR
#359](#359).
- Added robust tests for the `ENABLE_DIRECT_RESPONSE` environment
variable, covering both Elasticsearch and OpenSearch backends. Tests
gracefully handle missing backends by attempting to import both configs
and skipping if neither is available.
[#359](#359)

#### Changed
- Refactored database logic to reduce duplication
[#351](#351)
- Replaced `fastapi-slim` with `fastapi` dependency
[#351](#351)
- Changed minimum Python version to 3.9
[#354](#354)
- Updated stac-fastapi api, types, and extensions libraries to 5.1.1
from 3.0.0 and made various associated changes
[#354](#354)
- Changed makefile commands from 'docker-compose' to 'docker compose'
[#354](#354)
- Updated package names in setup.py files to use underscores instead of
periods for PEP 625 compliance
[#358](#358)
  - Changed `stac_fastapi.opensearch` to `stac_fastapi_opensearch`
  - Changed `stac_fastapi.elasticsearch` to `stac_fastapi_elasticsearch`
  - Changed `stac_fastapi.core` to `stac_fastapi_core`
  - Updated all related dependencies to use the new naming convention
- Renamed `docker-compose.yml` to `compose.yml` to align with Docker
Compose V2 conventions
[#358](#358)
- Removed deprecated `version` field from all compose files
[#358](#358)
- Updated `STAC_FASTAPI_VERSION` environment variables to 4.0.0 in all
compose files
[#362](#362)
- Bumped version from 4.0.0a2 to 4.0.0 for the PEP 625 compliant release
[#362](#362)
- Updated dependency requirements to use compatible release specifiers
(~=) for more controlled updates while allowing for bug fixes and
security patches
[#358](#358)
- Removed elasticsearch-dsl dependency as it's now part of the
elasticsearch package since version 8.18.0
[#358](#358)
- Updated test suite to use `httpx.ASGITransport(app=...)` for FastAPI
app testing (removes deprecation warning).
[#359](#359)
- Updated stac-fastapi parent libraries to 5.2.0.
[#359](#359)
- Migrated Elasticsearch index template creation from legacy
`put_template` to composable `put_index_template` API in
`database_logic.py`. This resolves deprecation warnings and ensures
compatibility with Elasticsearch 7.x and 8.x.
[#359](#359)
- Updated all Pydantic models to use `ConfigDict` instead of class-based
`Config` for Pydantic v2 compatibility. This resolves deprecation
warnings and prepares for Pydantic v3.
[#359](#359)
- Migrated all Pydantic `@root_validator` validators to
`@model_validator` for Pydantic v2 compatibility.
[#359](#359)
- Migrated startup event handling from deprecated
`@app.on_event("startup")` to FastAPI's recommended lifespan context
manager. This removes deprecation warnings and ensures compatibility
with future FastAPI versions.
[#361](#361)
- Refactored all boolean environment variable parsing in both
Elasticsearch and OpenSearch backends to use the shared `get_bool_env`
utility. This ensures robust and consistent handling of environment
variables such as `ES_USE_SSL`, `ES_HTTP_COMPRESS`, and
`ES_VERIFY_CERTS` across both backends.
[#359](#359)

#### Fixed
- Improved performance of `mk_actions` and `filter-links` methods
[#351](#351)
- Fixed inheritance relating to BaseDatabaseSettings and ApiBaseSettings
[#355](#355)
- Fixed delete_item and delete_collection methods return types
[#355](#355)
- Fixed inheritance relating to DatabaseLogic and BaseDatabaseLogic, and
ApiBaseSettings
[#355](#355)

**PR Checklist:**

- [x] Code is formatted and linted (run `pre-commit run --all-files`)
- [x] Tests pass (run `make test`)
- [x] Documentation has been updated to reflect changes, if applicable
- [x] Changes are added to the changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants