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

Allow custom models for search GET and items endpoints #271

Merged
merged 4 commits into from Oct 18, 2021

Conversation

lossyrob
Copy link
Member

@lossyrob lossyrob commented Sep 27, 2021

Description:
I use a different default limit than this project, which is 10. While currently you can override the search_request_model in the StacApi class, you can't do so for the models that give default values to the item collection endpoint and the GET search. This PR adds models that allow users to override these types. It also contains the ability for the pgstac backend to use a custom search model instead of building a PgstacSearch for the item collection and GET search endpoints. I made this change while tracking down why my overridden limit was not being used; this turns out not being needed for my specific use case (as the default limit comes from the arguments passed into the core client methods by ItemCollectionUri and SearchGetRequest), it seemed like a sensible change in case any other user would want to modify the behavior of the search model in more than just the search POST endpoint.

PR Checklist:

  • Code is formatted and linted (run pre-commit run --all-files)
  • 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.

Copy link
Collaborator

@moradology moradology left a comment

Choose a reason for hiding this comment

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

This looks good. There's some duplication of arguments but the fix (described in a below comment) might not be desirable. +1 if the duplication fix isn't something we want to pursue

@@ -27,6 +27,8 @@
class CoreCrudClient(AsyncBaseCoreClient):
"""Client for core endpoints defined by stac."""

search_request_model: Type[PgstacSearch] = attr.ib(init=False, default=PgstacSearch)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It might be possible to avoid this duplication of search_request_model specification if the client methods that use it were higher order functions. This would mean taking the StacApi specified search_request_model and returning a function which would then be registered as an endpoint.

Copy link
Member Author

Choose a reason for hiding this comment

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

Interesting point, perhaps a more broad pattern that could be applied in follow up work, but would likely take a larger refactor that may or may not be worth it.

@lossyrob lossyrob merged commit 6cef4d4 into master Oct 18, 2021
@geospatial-jeff geospatial-jeff deleted the fix/rde/pgstac-search-override branch August 1, 2022 21:28
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.

None yet

2 participants