Skip to content

Commit ac34b69

Browse files
committed
udpdate from main
2 parents 8e657ec + b20da94 commit ac34b69

File tree

9 files changed

+50
-26
lines changed

9 files changed

+50
-26
lines changed

CHANGES.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22

33
## [Unreleased]
44

5-
65
### Changed
76

87
- remove `child` links (`collections`) in landing page response
98

9+
## [5.0.3] - 2025-03-03
10+
11+
### Added
12+
13+
- added descriptive message to `types.search.str2bbox` length assert
14+
15+
### Fixed
16+
17+
- fix collection-search POST request model:
18+
- fix pydantic model to make sure class variables `_start_date` and `_end_date` not edited (ported from stac-pydantic)
19+
- fix bbox validation to allow anti-meridian crossing (ported from stac-pydantic)
20+
1021
## [5.0.2] - 2025-01-30
1122

1223
### Fixed
@@ -580,7 +591,8 @@ Full changelog: https://stac-utils.github.io/stac-fastapi/migrations/v3.0.0/#cha
580591

581592
* First PyPi release!
582593

583-
[Unreleased]: <https://github.com/stac-utils/stac-fastapi/compare/5.0.2..main>
594+
[Unreleased]: <https://github.com/stac-utils/stac-fastapi/compare/5.0.3..main>
595+
[5.0.3]: <https://github.com/stac-utils/stac-fastapi/compare/5.0.2..5.0.3>
584596
[5.0.2]: <https://github.com/stac-utils/stac-fastapi/compare/5.0.1..5.0.2>
585597
[5.0.1]: <https://github.com/stac-utils/stac-fastapi/compare/5.0.0..5.0.1>
586598
[5.0.0]: <https://github.com/stac-utils/stac-fastapi/compare/4.0.1..5.0.0>

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.0.2
1+
5.0.3

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ section-order = ["future", "standard-library", "third-party", "first-party", "lo
2424
quote-style = "double"
2525

2626
[tool.bumpversion]
27-
current_version = "5.0.2"
27+
current_version = "5.0.3"
2828
parse = """(?x)
2929
(?P<major>\\d+)\\.
3030
(?P<minor>\\d+)\\.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Library version."""
22

3-
__version__ = "5.0.2"
3+
__version__ = "5.0.3"

stac_fastapi/extensions/stac_fastapi/extensions/core/collection_search/request.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import attr
77
from fastapi import Query
8-
from pydantic import BaseModel, Field, field_validator
8+
from pydantic import BaseModel, Field, PrivateAttr, ValidationInfo, field_validator
99
from stac_pydantic.api.search import SearchDatetime
1010
from stac_pydantic.shared import BBox
1111
from typing_extensions import Annotated
@@ -64,8 +64,8 @@ class BaseCollectionSearchPostRequest(BaseModel):
6464

6565
# Private properties to store the parsed datetime values.
6666
# Not part of the model schema.
67-
_start_date: Optional[dt] = None
68-
_end_date: Optional[dt] = None
67+
_start_date: Optional[dt] = PrivateAttr(default=None)
68+
_end_date: Optional[dt] = PrivateAttr(default=None)
6969

7070
# Properties to return the private values
7171
@property
@@ -94,35 +94,33 @@ def validate_bbox(cls, v: BBox) -> BBox:
9494
raise ValueError(
9595
"Maximum elevation must greater than minimum elevation"
9696
)
97-
98-
if xmax < xmin:
99-
raise ValueError(
100-
"Maximum longitude must be greater than minimum longitude"
101-
)
97+
# Validate against WGS84
98+
if xmin < -180 or ymin < -90 or xmax > 180 or ymax > 90:
99+
raise ValueError("Bounding box must be within (-180, -90, 180, 90)")
102100

103101
if ymax < ymin:
104102
raise ValueError(
105103
"Maximum longitude must be greater than minimum longitude"
106104
)
107105

108-
# Validate against WGS84
109-
if xmin < -180 or ymin < -90 or xmax > 180 or ymax > 90:
110-
raise ValueError("Bounding box must be within (-180, -90, 180, 90)")
111-
112106
return v
113107

114-
@field_validator("datetime")
108+
@field_validator("datetime", mode="after")
115109
@classmethod
116-
def validate_datetime(cls, value: str) -> str:
110+
def validate_datetime(
111+
cls, value: Optional[str], info: ValidationInfo
112+
) -> Optional[str]:
117113
"""validate datetime."""
118114
# Split on "/" and replace no value or ".." with None
115+
if value is None:
116+
return value
119117
values = [v if v and v != ".." else None for v in value.split("/")]
120118

121119
# If there are more than 2 dates, it's invalid
122120
if len(values) > 2:
123121
raise ValueError(
124-
"""Invalid datetime range. Too many values.
125-
Must match format: {begin_date}/{end_date}"""
122+
"""Invalid datetime range. Too many values. """
123+
"""Must match format: {begin_date}/{end_date}"""
126124
)
127125

128126
# If there is only one date, duplicate to use for both start and end dates
@@ -149,8 +147,8 @@ def validate_datetime(cls, value: str) -> str:
149147
)
150148

151149
# Store the parsed dates
152-
cls._start_date = dates[0]
153-
cls._end_date = dates[1]
150+
info.data["_start_date"] = dates[0]
151+
info.data["_end_date"] = dates[1]
154152

155153
# Return the original string value
156154
return value
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Library version."""
22

3-
__version__ = "5.0.2"
3+
__version__ = "5.0.3"

stac_fastapi/extensions/tests/test_collection_search.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from datetime import datetime, timezone
23
from urllib.parse import quote_plus
34

45
import attr
@@ -88,6 +89,19 @@ def post_all_collections(
8889
return search_request.model_dump()
8990

9091

92+
def test_datetime_clean():
93+
# ref: https://github.com/stac-utils/stac-pydantic/issues/170
94+
utcnow = datetime.now(timezone.utc)
95+
utcnow_str = utcnow.isoformat()
96+
search = BaseCollectionSearchPostRequest(datetime=utcnow_str)
97+
assert search.start_date == utcnow
98+
assert search.end_date == utcnow
99+
100+
search = BaseCollectionSearchPostRequest()
101+
assert not search.start_date
102+
assert not search.end_date
103+
104+
91105
def test_collection_search_extension_default():
92106
"""Test GET - /collections endpoint with collection-search ext."""
93107
api = StacApi(

stac_fastapi/types/stac_fastapi/types/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def str2bbox(x: str) -> Optional[BBox]:
3535
"""Convert string to BBox based on , delimiter."""
3636
if x:
3737
t = tuple(float(v) for v in str2list(x))
38-
assert len(t) == 4
38+
assert len(t) == 4, f"BBox '{x}' must have 4 values."
3939
return t
4040

4141
return None
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Library version."""
22

3-
__version__ = "5.0.2"
3+
__version__ = "5.0.3"

0 commit comments

Comments
 (0)