Skip to content

Commit 14d7290

Browse files
Merge pull request #165 from stac-utils/fix-none-datetime
fix: validate search when datetime is none
2 parents a2a7b1a + ed2d2f3 commit 14d7290

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

Diff for: CHANGELOG.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
## Unreleased
33

4+
- Fix `Search` validation when `datetime` is `None` (#165, @gadomski)
5+
46
## 3.1.3 (2024-10-14)
57

68
- Add optional `numberMatched` and `numberReturned` to `api.collections.Collections` model to match the OGC Common part2 specification
@@ -121,18 +123,15 @@
121123
- Add option to skip validation of remote extensions (#16)
122124
- Add helper function for item validation (#17)
123125

124-
125126
## 1.0.3 (2020-06-03)
126127

127128
- Bugfixes (#10)
128129
- Add rel types enum (#11)
129130

130-
131131
## 1.0.2 (2020-06-02)
132132

133133
- Add models for the STAC API spec (#7)
134134

135-
136135
## 1.0.1 (2020-05-21)
137136

138137
- Allow extra asset-level fields (#1)

Diff for: stac_pydantic/api/search.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,10 @@ def validate_bbox(cls, v: BBox) -> BBox:
9898

9999
@field_validator("datetime")
100100
@classmethod
101-
def validate_datetime(cls, value: str) -> str:
101+
def validate_datetime(cls, value: Optional[str]) -> Optional[str]:
102102
# Split on "/" and replace no value or ".." with None
103+
if value is None:
104+
return value
103105
values = [v if v and v != ".." else None for v in value.split("/")]
104106

105107
# If there are more than 2 dates, it's invalid

Diff for: tests/api/test_search.py

+4
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,7 @@ def test_search_geometry_bbox():
149149
def test_search_invalid_bbox(bbox):
150150
with pytest.raises(ValidationError):
151151
Search(collections=["foo"], bbox=bbox)
152+
153+
154+
def test_search_none_datetime() -> None:
155+
Search(datetime=None)

0 commit comments

Comments
 (0)