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

WebAPI: Do not wrap result if offset is invalid #22174

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

userwiths
Copy link

@userwiths userwiths commented Jan 17, 2025

Closes #22158.

Description

On requests to /api/v2/torrents/info endpoint with an offset larger than the number of torrents, the offset defaults to 0 and returns results when its expected to return an error informing that this offset is out of range.

@Chocobo1 Chocobo1 added the WebAPI WebAPI-related issues/changes label Jan 19, 2025
@glassez glassez changed the title Do not wrap API result if offset is invalid. WebAPI: Do not wrap result if offset is invalid Jan 21, 2025
@userwiths userwiths requested a review from Chocobo1 January 27, 2025 12:48
@Chocobo1 Chocobo1 added this to the 5.1 milestone Jan 27, 2025
@glassez
Copy link
Member

glassez commented Jan 27, 2025

Could you summarize how it will behave after applying this patch?

Note that in the description of the PR, it is better to indicate how it will behave after merging it than just the problem itself (the description of the problem is generally redundant if there is a corresponding Issue to which it refers).

@userwiths
Copy link
Author

Yeah sure.

I will write down a few example cases below, but the main gist is that if a (positive) limit and (whatever) offset are provided, we return a list of items that overlap offset; offset + limit and - size; size -1 where - size and 0 are the first torrent and size-1 is the last one. If there is no overlap, we return an empty list.

If (negative) limit is provided we return a list of all torrents with index > offset (if offset is negative or 0 that is all torrents, if its 0 < offset < size - 1 we return all with index > offset and if offset > size we return an empty list.

So ... lets say we have 5 torrents.

limit=1&offset=0 => returns the first torrent.
limit=1&offset=4 => returns the last torrent.
limit=1&offset=5 => returns empty list [].
limit=1&offset=-1 => returns last torrent.
limit=1&offset=-5 => returns the first torrent.
limit=1&offset=-6 => returns empty list [].
limit=2&offset=-6 => returns the first torrent.
limit=3&offset=-6 => returns first two torrents.
offset=-6 => returns all available torrents.
offset=6 => returns empty list [].

Hope this explanation is good enough .

@glassez
Copy link
Member

glassez commented Jan 31, 2025

IIRC, now it doesn't match the following part of OP:

expected to return an error informing that this offset is out of range.

@userwiths
Copy link
Author

#22174 (comment)

It doesn't seem reasonable to make it an error in this case. If it is over-bound then returning an empty list would be enough IMO (as suggested in the linked issue #22158).

@glassez
Copy link
Member

glassez commented Jan 31, 2025

I just want to say about inconsistency between described expectations and end result. Either one or another should be adjusted.

P.S. I would just remove Description section from OP or replace it with description of how it is supposed to behave after merging this PR (as I suggested above).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebAPI WebAPI-related issues/changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Results wrap when using limit+offset on torrents/info API
3 participants