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

error with null datetime #77

Closed
jonhealy1 opened this issue May 19, 2021 · 6 comments · Fixed by #149
Closed

error with null datetime #77

jonhealy1 opened this issue May 19, 2021 · 6 comments · Fixed by #149

Comments

@jonhealy1
Copy link
Contributor

jonhealy1 commented May 19, 2021

I was looking at upgrading stac-pydantic and I noticed that it does not like: "datetime": null in a stac item. I got this error message running pytest as well. I think this line needs to be changed:

datetime: Union[dt, str] = Field(..., alias="datetime")

$ stac-pydantic validate-item https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/collectionless-item.json

1 validation error for CustomStacItem
properties -> datetime
  none is not an allowed value (type=type_error.none.not_allowed)
  • To get this error you need to change the version to '1.0.0-rc.4' in version.py
@jonhealy1
Copy link
Contributor Author

It says here that null is allowed for datetime: https://github.com/radiantearth/stac-spec/blob/v1.0.0-beta.2/item-spec/item-spec.md

@jonhealy1
Copy link
Contributor Author

jonhealy1 commented May 20, 2021

I tried this datetime: Union[dt, str] = Field(None, alias="datetime") but then this test fails test_validate_item_reraise_exception because it is allowing an item with no datetime key whatsoever to pass.

@geospatial-jeff
Copy link
Collaborator

geospatial-jeff commented May 20, 2021

I think maybe we can update the ItemProperties.datetime type to 'Optional[datetime] = Field(...)'

The '...' indicates the field is required, so a user has to explicitely pass 'None'. I don't have the pydantic docs in front of me (I'm on mobile atm) but I think this is how it works.

This is kind of related to #74 and #75

@jonhealy1
Copy link
Contributor Author

Do you think that in "datetime": null, the problem is that null should be None for Python?

@kylebarron
Copy link
Contributor

A JSON null is equivalent to a Python None. When you call json.load on that JSON document, you'll get 'datetime': None

alukach added a commit to alukach/stac-pydantic that referenced this issue Jul 21, 2022
As mentioned in stac-utils#77, we should permit a None value for datetime property under certain circumstances.
@alukach
Copy link

alukach commented Jul 21, 2022

I do believe that we should instead be expecting None rather than "null". See #116 for a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants