Skip to content
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

fix: validate search when datetime is none #165

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

## Unreleased

- Fix `Search` validation when `datetime` is `None` (#165, @gadomski)

## 3.1.3 (2024-10-14)

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


## 1.0.3 (2020-06-03)

- Bugfixes (#10)
- Add rel types enum (#11)


## 1.0.2 (2020-06-02)

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


## 1.0.1 (2020-05-21)

- Allow extra asset-level fields (#1)
Expand Down
4 changes: 3 additions & 1 deletion stac_pydantic/api/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ def validate_bbox(cls, v: BBox) -> BBox:

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

# If there are more than 2 dates, it's invalid
Expand Down
4 changes: 4 additions & 0 deletions tests/api/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,7 @@ def test_search_geometry_bbox():
def test_search_invalid_bbox(bbox):
with pytest.raises(ValidationError):
Search(collections=["foo"], bbox=bbox)


def test_search_none_datetime() -> None:
Search(datetime=None)
Loading