-
Notifications
You must be signed in to change notification settings - Fork 112
Add bbox and datetime to /collections/{collectionId}/items #477
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
Imported str2list function from stac_fastapi.types.search as already have dependency on it.
Using same type signature as get_search
Used the same base_args -> clean from the search routes Probably not necessary in this situation but thought I'd keep it similar (and extensible).
debac82
to
158e2c4
Compare
Some comments:
Then three separate points that probably need attention:
|
Copy the bbox and datetime filtering from the search routes
@@ -123,6 +124,8 @@ class ItemCollectionUri(CollectionUri): | |||
"""Get item collection.""" | |||
|
|||
limit: int = attr.ib(default=10) | |||
bbox: Optional[str] = attr.ib(default=None, converter=str2list) |
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.
Would it make sense to convert this directly to e.g. Optional[List[float]]
for bbox and Optional[List[Union[datetime, None]]]
for datetime so that you don't need to handle the conversion issues downstream?
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.
Yes I mentioned that in my comment above point 3.
I held off on changing it until I get some feedback, as that is the current behavior in the similar routes.
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.
datetime
is a little more complicated, because it also supports ranges like 2020-01-01/2022-01-01
or 2020-01-01/..
, so it must allow str
input (or a clever pydantic type enforcing either datetime or something with a slash in it).
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.
Ah, I did not see that comment. Still, a list of datetime/None should work. None could be used for open date ranges as specified also for STAC extents in collections...
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.
Oh sorry I misunderstood you. Yes that makes sense, but as I've looked into this I've found some inconsistency.
For sqlalchemy
, I added code based on the post_search implementation: it has some complicated logic on deciding how to treat the datetime
parameter, and treats a single datetime as an exact datetime. It's also more lenient on datetime formatting.
For pgstac
, I just used post_request_model
, which treats a single value as an end-date, and is stricter on enforcing RFC3339.
So a few questions:
- Should we update the
sqlalchemy
post_search
anditem_collection
routes to usepost_request_model
? - Should a single datetime be considered as an end date? It seems much more useful (if less obvious) than the unlikely case you're able to hit on the exact datetime of an item...
- If the latter, datetime could be typed as (being pedantic):
None | tuple[datetime, datetime] | tuple[datetime, None] | tuple[None, datetime]
. This is all already validated inpost_request_model
(see the last link above). I think actually enforcing this typing would break the pgstac implementation, as it passes the rawdatetime/datetime
string to the DB'ssearch
function.
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.
Should we update the sqlalchemy post_search and item_collection routes to use post_request_model?
I think the sqlalchemy backend would be better if, like pgstac, it had one function (_search_base
) which contains most of the important query logic and is wrapped by all of the other methods.
Should a single datetime be considered as an end date? It seems much more useful (if less obvious) than the unlikely case you're able to hit on the exact datetime of an item...
My interpretation of the OAF datetime parameter is a single date time is an exact date time (==
) while date time ranges are either ../end_date
or start_date/..
. I agree that ==
is arguably less useful when searching than a datetime range but the distinction is there to let users do both.
If the latter, datetime could be typed as (being pedantic): None | tuple[datetime, datetime] | tuple[datetime, None] | tuple[None, datetime]. This is all already validated in post_request_model (see the last link above). I think actually enforcing this typing would break the pgstac implementation, as it passes the raw datetime/datetime string to the DB's search function.
Lol I should have read this thread first, I proposed the same thing in PR comment below. We shouldn't be too concerned about breaking backend implementations w/ changes to the API layer as long as those changes make the API layer stronger and improve separation of concerns (I think here they do). Backend implementations shouldn't have to guess what information is included in a request, that information should be presented in a way that is clear and easy to use and I'm not in love with the current solution for datetime. Pgstac can always coerce these back to a string.
Sorry its taken me a while to get around to this.
I agree that the
Parameters aim to use the same language as what is in the API spec for clarity. I'm fine changing this but I don't think its too straight forward. Pydantic does support aliasing but I don't believe attrs does.
I agree with all of this, |
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.
This LGTM, thanks for the PR! We can continue discussion in this PR, but if its okay with you @carderne I think any other changes should become new issues / new PRs.
Sounds good! To sort-of summarise the other issues:
|
@geospatial-jeff I don’t think I can merge this |
Fixed conflicts introduced by #482. |
Fixed the linting issue from the merge above |
Just bumping, any reason not to merge? |
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.
Sorry, didn't see this until just now. Looks good to me.
Related Issue(s):
Description:
Add
bbox
anddatetime
query parameters to the/collections{collection_id}/items
route.Updated base classes, request models and pgstac and sqlalchemy clients.
PR Checklist:
pre-commit run --all-files
)make test
)make docs
)