-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Fixes: #18150 - Get pagination limit with default 0 #18151
Conversation
Documentation on the parameters: https://demo.netbox.dev/static/docs/rest-api/overview/
|
My take:
|
…T, MAX_PAGE_SIZE)
Can this bug be resolved simply by checking that the configured |
@jeremystretch This update leaves the original logic intact but just ensures that
|
@bctiemann I was thinking we could just compare |
@jeremystretch I think you're right; after working through the use cases I think this does solve it. Note this also puts both variables explicitly into |
Also note that I'm leaving the unit test changes in place because with |
Reverting to the previous solution (validating the two variables against each other in |
Fixes: #18150
If
limit
is not specified in an API list view, the value raises aKeyError
which is silently swallowed without processingMAX_PAGE_SIZE
, leading to inconsistent pagination results. This change uses.get()
with a default of 0 to ensure no exception is raised and the configured page limit is enforced.Specifically: in our current behavior, we have these scenarios:
With this behavior, if a script hits a list endpoint with no
limit
, thenext
URL will be paginated byPAGINATE_COUNT
; but if the script follows that link, the next page will use thelimit=n
case, and the overall page count andnext
andprevious
links are paginated byMAX_PAGE_SIZE
rather thanPAGINATE_COUNT
, which would re-flow all the pages and potentially lead to miscounts or other unexpected script behavior. This can be worked around by a script always specifying alimit
, but it seems more sensible for omittinglimit
to be consistent withlimit=0
.After this change:
Open question(s):
limit=0
being a synonym for "unlimited" more intuitive than havinglimit=0
behave the same as omittinglimit
?limit=0
being interpreted aslimit=50
be surprising to the user?NOTE: The fix has changed; leaving the above to preserve the discussion history.
This fix maintains the existing (separate) behaviors of
limit=0
andlimit
omitted. However, it changes the "limit
omitted" case to returnmin(PAGINATE_COUNT, MAX_PAGE_SIZE)
, i.e. to ensureMAX_PAGE_SIZE
is enforced.