-
Notifications
You must be signed in to change notification settings - Fork 27
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
update pagination for collection-search #155
base: main
Are you sure you want to change the base?
Conversation
I'm also seeing some warning
coming from stac-fastapi-pgstac/stac_fastapi/pgstac/app.py Lines 72 to 76 in 9a3797a
CollectionSearchExtension is trying to use some extension that has nothing to do with the collection-search (I though we splited the extension list at one point to avoid this @hrodmn
|
I'm sorry for missing this in that PR!
You added that warning in stac-fastapi. We could limit the list of extensions that we pass to |
The problem is that the In the short term it probably makes most sense to handle the collection links in a specific way, though it might make sense to update |
One way to handle it would be to create a new @attr.s
class CollectionSearchPagingLinks(BaseLinks):
next: Optional[Dict[str, Any]] = attr.ib(kw_only=True, default=None)
prev: Optional[Dict[str, Any]] = attr.ib(kw_only=True, default=None)
def link_next(self) -> Optional[Dict[str, Any]]:
"""Create link for next page."""
if self.next is not None:
method = self.request.method
if method == "GET":
# if offset is equal to default value (0), drop it
if self.next["body"].get("offset", -1) == 0:
_ = self.next["body"].pop("offset")
href = merge_params(self.url, self.next["body"])
# if next link is equal to this link, skip it
if href == self.url:
return None
link = {
"rel": Relations.next.value,
"type": MimeTypes.geojson.value,
"method": method,
"href": href,
}
return link
return None
def link_prev(self):
if self.prev is not None:
method = self.request.method
if method == "GET":
# if offset is equal to default value (0), drop it
if self.prev["body"].get("offset", -1) == 0:
_ = self.prev["body"].pop("offset")
href = merge_params(self.url, self.prev["body"])
# if prev link is equal to this link, skip it
if href == self.url:
return None
return {
"rel": Relations.previous.value,
"type": MimeTypes.geojson.value,
"method": method,
"href": href,
}
return None It would require some logic to check if we need to pass the next/prev links at a given page (i.e. compare the |
Here is one approach to fixing the problem in stac-fastapi-pgstac: #156. It still needs some work to get the Actually, the request model does not have |
* handle collection paging differently * test next link
Thanks for merging #156 @vincentsarago! There is still some work to be done here unfortunately. stac-fastapi expects a I think we either need to add the |
I just noticed that in stac-fastapi we only limit the conformance classes in the That is why the |
One option is to turn pagination off in stac-fastapi-pgstac collection search for now then either implement |
@hrodmn so there is no hard specification about the pagination in the collection-search but for sure we can't use the we should:
OR we could also see if @bitner wants to change pgstac to use |
@@ -55,6 +56,9 @@ | |||
"sort": SortExtension(), | |||
"fields": FieldsExtension(), | |||
"filter": FilterExtension(client=FiltersClient()), | |||
# NOTE: there is no conformance class for the Pagination extension | |||
# so `CollectionSearchExtension.from_extensions` will raise a warning | |||
"pagination": OffsetPaginationExtension(), |
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.
@@ -120,10 +125,13 @@ async def all_collections( # noqa: C901 | |||
|
|||
linked_collections.append(coll) | |||
|
|||
links = await PagingLinks( | |||
if not collections: | |||
next_link = None |
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.
pgstac seems to return a next link even if returned collection is empty
cc @bitner
assert len(cols) == 2 | ||
# TODO: Check with pgstac | ||
# assert len(links) == 2 | ||
# assert {"root", "self"} == {link["rel"] for link in links} |
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.
there seems to be bugs in pgstac about how next/previous links are created
should open an issue in pgstac repo
this PR adds a tests showing that the recent collection-search addition breaks the pagination code
cc @hrodmn