-
Notifications
You must be signed in to change notification settings - Fork 31
add datetime validation for collection time intervals #177
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: should we validate interval values themself? (e.g [0] < [1] and sub-intervals)
My instinct is yes? One of the values of stac-pydantic over pure json-schema is the ability to easily do checks like this.
) | ||
|
||
return v | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved ☝️ to shared
stac_pydantic/collection.py
Outdated
min_length=1, | ||
), | ||
AfterValidator(validate_time_interval), | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gadomski
I'm trying to understand the spec here but looking at the json-schema I feel ☝️ respect the specification
- interval HAS TO be an array of at least 1 item
[[]]
- interval items HAVE to be an array or 2 Datetime|None value
[[date, None], ...]
# previous
TimeInterval(interval=[]) # OK
TimeInterval(interval=[[]]) # OK
TimeInterval(interval=[['yo']]) # OK
# now
TimeInterval(interval=[])
ValidationError: 1 validation error for TimeInterval
interval
List should have at least 1 item after validation, not 0 [type=too_short, input_value=[], input_type=list]
For further information visit https://errors.pydantic.dev/2.11/v/too_short
TimeInterval(interval=[[]])
ValidationError: 1 validation error for TimeInterval
interval.0
List should have at least 2 items after validation, not 0 [type=too_short, input_value=[], input_type=list]
For further information visit https://errors.pydantic.dev/2.11/v/too_short
TimeInterval(interval=[['yo']])
ValidationError: 1 validation error for TimeInterval
interval.0.0
Input should be a valid datetime or date, input is too short [type=datetime_from_date_parsing, input_value='yo', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/datetime_from_date_parsing
👇 https://github.com/radiantearth/stac-spec/blob/v1.0.0/collection-spec/json-schema/collection.json#extent-object
cc @alinbutu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just tried pystac
validation and new behaviour seems 👍
stac_pydantic/collection.py
Outdated
|
||
|
||
class TimeInterval(StacBaseModel): | ||
""" | ||
https://github.com/radiantearth/stac-spec/blob/v1.0.0/collection-spec/collection-spec.md#temporal-extent-object | ||
""" | ||
|
||
interval: List[List[Union[str, None]]] | ||
interval: Annotated[ # type: ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for some reason Mypy doesn't like conlist=
closes #176
Q: should we validate interval values themself? (e.g
[0] < [1]
and sub-intervals)