-
Notifications
You must be signed in to change notification settings - Fork 100
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
Improve RFC 3339 datetime handling #368
Changes from 23 commits
eb8f9b0
7a751fe
15b6ff6
eec3971
0c9b56e
17fb42d
6666af5
1238bc1
36e5bdd
e36a8c9
94af4e7
755220d
0f27bfc
45747f5
d933be7
c9f943c
afb4176
7b00142
c9b83de
b9119b4
9f400f4
f325ebb
a77d05e
d535c32
b7a527c
c7b1a8e
11e55f7
cb2676a
8a433e8
73c32d9
35357e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
"""Serializers.""" | ||
import abc | ||
import json | ||
from datetime import datetime | ||
from typing import TypedDict | ||
|
||
import attr | ||
import geoalchemy2 as ga | ||
from stac_pydantic.shared import DATETIME_RFC339 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DATETIME_RFC339 has been deprecated in stac_pydantic. It has several problems including, not parsing fractional seconds or timezones other than Z. |
||
from pystac.utils import datetime_to_str | ||
|
||
from stac_fastapi.sqlalchemy.models import database | ||
from stac_fastapi.types import stac as stac_types | ||
from stac_fastapi.types.config import Settings | ||
from stac_fastapi.types.links import CollectionLinks, ItemLinks, resolve_links | ||
from stac_fastapi.types.rfc3339 import now_to_rfc3339_str, rfc3339_str_to_datetime | ||
|
||
|
||
@attr.s # type:ignore | ||
|
@@ -55,7 +55,7 @@ def db_to_stac(cls, db_model: database.Item, base_url: str) -> stac_types.Item: | |
# Use getattr to accommodate extension namespaces | ||
field_value = getattr(db_model, field.split(":")[-1]) | ||
if field == "datetime": | ||
field_value = field_value.strftime(DATETIME_RFC339) | ||
field_value = datetime_to_str(field_value) | ||
properties[field] = field_value | ||
item_id = db_model.id | ||
collection_id = db_model.collection_id | ||
|
@@ -101,12 +101,12 @@ def stac_to_db( | |
# Use getattr to accommodate extension namespaces | ||
field_value = stac_data["properties"][field] | ||
if field == "datetime": | ||
field_value = datetime.strptime(field_value, DATETIME_RFC339) | ||
field_value = rfc3339_str_to_datetime(field_value) | ||
indexed_fields[field.split(":")[-1]] = field_value | ||
|
||
# TODO: Exclude indexed fields from the properties jsonb field to prevent duplication | ||
|
||
now = datetime.utcnow().strftime(DATETIME_RFC339) | ||
now = now_to_rfc3339_str() | ||
if "created" not in stac_data["properties"]: | ||
stac_data["properties"]["created"] = now | ||
stac_data["properties"]["updated"] = now | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
"attrs", | ||
"pydantic[dotenv]", | ||
"stac_pydantic==2.0.*", | ||
"pystac==1.*", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it took me 2 hours to figure out that the docs broke because I'd added an import from pystac, but it's not a dependency of this package. The tests worked because everything gets installed when they run. |
||
"ciso8601~=2.2.0", | ||
] | ||
|
||
extra_reqs = { | ||
|
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.
-e
isn't needed in this case, and it only affects the first package name after it (rather than all of them)