Skip to content

Conversation

@Frosty2500
Copy link

Adds pagination via a cursor and limit functionality.

Copy link

@jkhsjdhjs jkhsjdhjs left a comment

Choose a reason for hiding this comment

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

Looks pretty good so far, but I still have some comments on this one. Also, slicing isn't currently implemented for AAS, can you add this?

Copy link

@jkhsjdhjs jkhsjdhjs left a comment

Choose a reason for hiding this comment

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

Some things I just noticed while testing the implementation:

  • In case less than cursor items are returned, the cursor is returned as 10 anyway. We should discuss whether a cursor should be returned in these cases as all, as there should be a way to indicate to the client that there aren't any further objects it can request. Maybe the cursor should be omitted if there aren't any further items to request, or set to -1 or something else?
  • Invalid cursor/limit values (e.g. non-numeric values) are currently silently ignored. We should return a 400 instead to make the client aware of its errors.
  • Negative numbers for cursor or limit currently cause an internal server error. We should instead also return 400 for negative values, as they are equally invalid.
  • XML result responses are wrapped in a response object, which they shouldn't IMO.

@Frosty2500
Copy link
Author

Frosty2500 commented Apr 30, 2024

I'm not sure if I agree with your first point. While it isn't optimal I think it is quite obvious to the user when there are no more objects to request. But it would still be nice to know where you ended with your request, maybe you want to POST an element between the requests and then continue with the cursor of the old request. I'm not sure if cursor information is completly useless even if it lies outside the existing number of elements. But I'm definitely open to changing it, I'm just not sure how.

The rest are alle good points I'll implement them, thanks 😄

@Frosty2500 Frosty2500 closed this Apr 30, 2024
@Frosty2500 Frosty2500 reopened this Apr 30, 2024
Comment on lines 589 to 592
limit_str= request.args.get('limit', type=str, default="10")
cursor_str= request.args.get('cursor', type=str, default="0")
if not limit_str.isdigit() or not cursor_str.isdigit():
raise BadRequest("Cursor and limit must be positive integers!")

Choose a reason for hiding this comment

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

While the code is probably the shortest possible, I don't like that limit and cursor are retrieved twice, and also have the default values specified in two separate lines. What about the following instead:

limit = request.args.get('limit', default="10")
cursor = request.args.get('cursor', default="0")
try:
    limit, cursor = int(limit), int(cursor)
    if limit < 0 or cursor < 0:
        raise ValueError
except ValueError:
    raise BadRequest("Cursor and limit must be positive integers!")

Copy link
Author

Choose a reason for hiding this comment

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

I also like the above more 👍

Copy link

@jkhsjdhjs jkhsjdhjs left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@jkhsjdhjs jkhsjdhjs merged commit 1d70049 into feature/http_api May 14, 2024
@Frosty2500 Frosty2500 deleted the http_api/implement_pagination branch September 17, 2024 17:10
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.

3 participants