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

Update pagination to work with pgstac 0.9.X #140

Merged

Conversation

zstatmanweil
Copy link
Contributor

Related Issue(s):

Description:

pgstac v0.9.x now returns prev and next tokens as links in the search returned from the database. This means the current version of the service with the most recent pgstac backend doesn't properly allow for pagination. The links returned by pgstac v0.9.x are formatted with a GET method request. At first I just passed in the search response's links as extra_links here in the code, which worked with GET requests but does not work with the formatting for POST requests. To simplify, I am now extracting the next and prev token from the links if they exist and don't change how they are handled in the rest of the code.

I ensured tests passed with v0.8.5 and v0.9.1. I also ran GET and POST searches for both and confirmed the link responses were the same.
v0.8.5 GET

   {
      "rel":"next",
      "type":"application/geo+json",
      "method":"GET",
      "href":"http://localhost:8082/search?collection=joplin&token=next:joplin:d4eccfa2-7d77-4624-9e2a-3f59102285bb"
   },
   {
      "rel":"root",
      "type":"application/json",
      "href":"http://localhost:8082/"
   },
   {
      "rel":"self",
      "type":"application/json",
      "href":"http://localhost:8082/search?collection=joplin"
   }
]

0.9.1 GET

   {
      "rel":"root",
      "type":"application/json",
      "href":"http://localhost:8082/"
   },
   {
      "rel":"self",
      "type":"application/json",
      "href":"http://localhost:8082/search?collection=joplin"
   },
   {
      "rel":"next",
      "href":"http://localhost:8082/search?collection=joplin&token=next:joplin:d4eccfa2-7d77-4624-9e2a-3f59102285bb"
      "type":"application/geo+json",
      "method":"GET"
   }
]

0.8.5 POST

"links": [
        {
            "rel": "next",
            "type": "application/geo+json",
            "method": "POST",
            "href": "http://localhost:8082/search",
            "body": {
                "collections": [
                    "joplin"
                ],
                "sortby": [
                    {
                        "field": "properties.eo:cloud_cover",
                        "direction": "desc"
                    }
                ],
                "limit": 5,
                "token": "next:joplin:f2cca2a3-288b-4518-8a3e-a4492bb60b08"
            }
        },
        {
            "rel": "root",
            "type": "application/json",
            "href": "http://localhost:8082/"
        },
        {
            "rel": "self",
            "type": "application/json",
            "href": "http://localhost:8082/search"
        }
    ]

0.9.0 POST

"links": [
        {
            "rel": "next",
            "type": "application/geo+json",
            "method": "POST",
            "href": "http://localhost:8082/search",
            "body": {
                "collections": [
                    "joplin"
                ],
                "sortby": [
                    {
                        "field": "properties.eo:cloud_cover",
                        "direction": "desc"
                    }
                ],
                "limit": 5,
                "token": "next:joplin:f2cca2a3-288b-4518-8a3e-a4492bb60b08"
            }
        },
        {
            "rel": "root",
            "type": "application/json",
            "href": "http://localhost:8082/"
        },
        {
            "rel": "self",
            "type": "application/json",
            "href": "http://localhost:8082/search"
        }
    ]

PR Checklist:

  • pre-commit hooks pass locally
  • Tests pass (run make test)
  • Documentation has been updated to reflect changes, if applicable, and docs build successfully (run make docs)
  • Changes are added to the CHANGELOG.

@zstatmanweil
Copy link
Contributor Author

I see the goal right now is probably to get 3.0.0 released so we can wait to merge this in until after that if folks like this change.

@vincentsarago
Copy link
Member

thanks @zstatmanweil this looks great 🙏

I see the goal right now is probably to get 3.0.0 released so we can wait to merge this in until after that if folks like this change.

yeah, I've just pushed the release. I'll be back from holidays next week and I'll look at this PR 🙏

@zstatmanweil
Copy link
Contributor Author

hey @vincentsarago ! Any thoughts on this PR?

@vincentsarago
Copy link
Member

vincentsarago commented Sep 3, 2024

sorry @zstatmanweil I let this slipped 😓

I think the PR looks good but we would need to add tests

First I think we will need to update the tests suite to be able to test multiple version of pgstac. I can work on this early next week

@zstatmanweil
Copy link
Contributor Author

No worries! I assumed, which is why I bugged. Ok sounds good, let me know if/how I can help.

@@ -17,13 +17,13 @@
"buildpg",
"brotli_asgi",
"pygeofilter>=0.2",
"pypgstac==0.8.*",
"pypgstac>=0.8,<0.10",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stac-fastapi-pgstac should be compatible with 0.8 and 0.9

]

extra_reqs = {
"dev": [
"pystac[validation]",
"pypgstac[psycopg]==0.8.*",
"pypgstac[psycopg]==0.9.*",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use pgstac 0.9.x in tests

@vincentsarago
Copy link
Member

@zstatmanweil I'll try to merge this week but we need to fix some issue with collection-search #155

@zstatmanweil
Copy link
Contributor Author

Thanks for the update @vincentsarago !

@vincentsarago
Copy link
Member

well it seems that we will get this PR merged first before #155

@vincentsarago vincentsarago force-pushed the pagination-for-recent-pgstac-versions branch from 0c5f2ad to 1b3e871 Compare October 14, 2024 15:41
@vincentsarago vincentsarago self-requested a review October 14, 2024 15:57
@vincentsarago vincentsarago merged commit b1cb99f into stac-utils:main Oct 14, 2024
7 checks passed
@zstatmanweil
Copy link
Contributor Author

@vincentsarago , do you know when you might cut a new release? I can always use "latest" if it isn't going to be soon.

@vincentsarago
Copy link
Member

I'm waiting on a pastac release to finish some other PR
sorry about the delay

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

Successfully merging this pull request may close these issues.

2 participants