-
Notifications
You must be signed in to change notification settings - Fork 52
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
Sort envs returned by REST API by current build's scheduled_on time #881
base: main
Are you sure you want to change the base?
Sort envs returned by REST API by current build's scheduled_on time #881
Conversation
✅ Deploy Preview for conda-store canceled.
|
7a9b540
to
0d57b2b
Compare
871e0e3
to
0442238
Compare
After a discussion, it seems like no matter how we solve this there's going to be a breaking change to the API. Cursor-based pagination will allow for any sorting order, so I'll look into implementing that, probably through |
Adding pagination via |
9e55051
to
847eed4
Compare
Hot reloading's done, but the |
7b5a0bc
to
dd5a139
Compare
9c14e99
to
466ac3b
Compare
2edfff6
to
9c21efa
Compare
9c21efa
to
43c63c2
Compare
b673196
to
54f7907
Compare
ee054f0
to
2c88c59
Compare
664d122
to
63db9d0
Compare
63db9d0
to
d5a8846
Compare
Not sure if this is actually ready to be merged, as it is not currently compatible with the frontend, and a discussion about REST API versioning needs to be had before this approach can be merged. But otherwise, tests are passing and the implementation is I think mostly complete :) @soapy1 |
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.
Looking good! Thank you for adding such beautiful formatted and thorough docs to a lot of these functions 🤩
Just a few things to sort out.
I took notes on what I tested manually in this gist https://gist.github.com/soapy1/beae935f78725cfd1dd0897c1ce016d4
"name": orm.Environment.name, | ||
}, | ||
default_sort_by=["namespace", "name"], | ||
paginated, next_cursor, count = paginate( |
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.
It looks like responses for this endpoint includes the current_build
, Previously this endpoint didn't include that field in the output.
I think this is an ok change, but calling it in case this was not intentional.
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.
The current_build
field is an optional field in the Environment
model, so originally I thought there's no harm in allowing it to be returned here unless there's some specific reason to strip it out. Do you think this was intended to make the response smaller?
Anyway, the current_build_id
is kept here, and FastAPI has a way of excluding fields so I've just made use of that to capture the old behavior.
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.
Do you think this was intended to make the response smaller?
could be?
columns = [] | ||
if order_by: | ||
for order_name in order_by: | ||
idx = self.order_names.index(order_name) |
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.
It would be good to have some error handling for if users provide bad sort_by
arguments (or do some validation on the validity of the arguments earlier in the call).
Currently, if you provide a bad sort_by
argument it causes an internal server error:
$ curl http://localhost:8080/conda-store/api/v1/environment/\?limit\=100\&sort_by\=oops
Internal Server Error%
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.
Ahh, thanks for this - I've added error handling and a test for bad query parameters!
from conda_store_server.conda_store import CondaStore | ||
from conda_store_server.exception import CondaStoreError | ||
from conda_store_server.server import schema as auth_schema | ||
from conda_store_server.server.auth import Authentication | ||
from conda_store_server.server.schema import AuthenticationToken, Permissions | ||
|
||
|
||
def get_cursor(cursor: Optional[str] = None) -> Cursor: |
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.
Whats the motivation for separating the the cursor
from the rest of the pagination args?
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's really no reason other than that the cursor based pagination takes a lot more code than limit/offset, so I've broken that off into a separate module, so that views/api.py
is mostly endpoints. If it makes more sense to keep this as part of views/api.py
I'm happy to do so, however.
return Cursor.load(cursor) | ||
|
||
|
||
def get_cursor_paginated_args( |
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.
It looks like most of these depends
type functions are in the conda_store_server/_internal/server/dependencies
module. I think it would be good to consolidate these into that module.
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.
Totally agree, thank you!
One more question (related to how we want to approach versioning for this change): how do we want to approach pagination for the rest of the api? Do we want all the other endpoints to also adopt this type of pagination? |
I vote yes - as far as I can tell the advantages of limit/offset are that it's easy to implement, but the cost of it is exactly what is described in #859. Cursor based pagination addresses that. |
Fixes #859.
Description
This PR sorts environments returned when a GET is sent to
/environment/
by the time the environments' current builds were submitted. In systems where users are creating environments while environments are being queried, this ensures that all results are returned; other sorting methods (e.g. by name) can yield incomplete results.Pull request checklist