-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fixes: #18150 - Get pagination limit with default 0 #18151
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
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
limitis not specified in an API list view, the value raises aKeyErrorwhich 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, thenextURL will be paginated byPAGINATE_COUNT; but if the script follows that link, the next page will use thelimit=ncase, and the overall page count andnextandpreviouslinks are paginated byMAX_PAGE_SIZErather 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 omittinglimitto be consistent withlimit=0.After this change:
Open question(s):
limit=0being a synonym for "unlimited" more intuitive than havinglimit=0behave the same as omittinglimit?limit=0being interpreted aslimit=50be 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=0andlimitomitted. However, it changes the "limitomitted" case to returnmin(PAGINATE_COUNT, MAX_PAGE_SIZE), i.e. to ensureMAX_PAGE_SIZEis enforced.