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

allow null datetime #149

Merged
merged 3 commits into from
May 21, 2024
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
12 changes: 1 addition & 11 deletions stac_pydantic/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
from pydantic import AnyUrl, ConfigDict, Field, model_serializer, model_validator

from stac_pydantic.links import Links
from stac_pydantic.shared import (
SEMVER_REGEX,
Asset,
StacBaseModel,
StacCommonMetadata,
UtcDatetime,
)
from stac_pydantic.shared import SEMVER_REGEX, Asset, StacBaseModel, StacCommonMetadata
from stac_pydantic.version import STAC_VERSION


Expand All @@ -19,10 +13,6 @@ class ItemProperties(StacCommonMetadata):
https://github.com/radiantearth/stac-spec/blob/v1.0.0/item-spec/item-spec.md#properties-object
"""

# Overide the datetime field to be required
datetime: Optional[UtcDatetime]

# Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information.
model_config = ConfigDict(extra="allow")


Expand Down
2 changes: 1 addition & 1 deletion stac_pydantic/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class StacCommonMetadata(StacBaseModel):
title: Optional[str] = None
description: Optional[str] = None
# Date and Time
datetime: Optional[UtcDatetime] = None
datetime: Optional[UtcDatetime] = Field(...)
created: Optional[UtcDatetime] = None
updated: Optional[UtcDatetime] = None
# Date and Time Range
Expand Down
2 changes: 1 addition & 1 deletion tests/example_stac/datetimerange.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
]
},
"properties":{
"datetime":"2018-01-01T13:21:30Z",
"datetime":null,
"start_datetime":"2018-01-01T13:21:30Z",
"end_datetime":"2018-01-01T13:31:30Z"
},
Expand Down
10 changes: 10 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ def test_stac_common_dates(args) -> None:
StacCommonMetadata(**args)


def test_stac_null_datetime_required() -> None:
with pytest.raises(ValidationError):
StacCommonMetadata(
**{
"start_datetime": "2024-01-01T00:00:00Z",
"end_datetime": "2024-01-02T00:00:00Z",
}
)


@pytest.mark.parametrize(
"args",
[
Expand Down
Loading