The REST API paginator should raise an exception if attempting to paginate an unordered queryset #10892

Closed
opened 2025-12-29 21:37:22 +01:00 by adam · 3 comments
Owner

Originally created by @jeremystretch on GitHub (Mar 13, 2025).

Originally assigned to: @jnovinger on GitHub.

Proposed Changes

Our OptionalLimitOffsetPagination pagination class should raise an exception whenever pagination is attempted on a queryset with no ordering applied.

Justification

This change was prompted by bug #18729. A queryset with no ordering applied (e.g. because of an applied annotation) is nondeterministic. Paginating through such a queryset is unreliable; an object can appear on multiple pages. Raising an exception exposes this dangerous condition.

Originally created by @jeremystretch on GitHub (Mar 13, 2025). Originally assigned to: @jnovinger on GitHub. ### Proposed Changes Our [`OptionalLimitOffsetPagination`](https://github.com/netbox-community/netbox/blob/ed135102bed0733c4dff90206f3d142494d900fb/netbox/netbox/api/pagination.py#L7) pagination class should raise an exception whenever pagination is attempted on a queryset with no ordering applied. ### Justification This change was prompted by bug #18729. A queryset with no ordering applied (e.g. because of an applied annotation) is nondeterministic. Paginating through such a queryset is unreliable; an object can appear on multiple pages. Raising an exception exposes this dangerous condition.
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:37:22 +01:00
adam closed this issue 2025-12-29 21:37:22 +01:00
Author
Owner

@atownson commented on GitHub (Mar 14, 2025):

Would it be possible to get a comprehensive list of endpoints that would be affected? Based on the other issue, it looks like querysets within views that use the annotate aggregation. But is this the only method that would affect the ordering?

@atownson commented on GitHub (Mar 14, 2025): Would it be possible to get a comprehensive list of endpoints that would be affected? Based on the other issue, it looks like querysets within views that use the annotate aggregation. But is this the only method that would affect the ordering?
Author
Owner

@github-actions[bot] commented on GitHub (Jun 13, 2025):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Jun 13, 2025): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/main/CONTRIBUTING.md).
Author
Owner

@jnovinger commented on GitHub (Jul 23, 2025):

Would it be possible to get a comprehensive list of endpoints that would be affected? Based on the other issue, it looks like querysets within views that use the annotate aggregation. But is this the only method that would affect the ordering?

The following API endpoints appear to be affected:

  • /api/extras/tagged-objects/
  • /api/users/tokens/
@jnovinger commented on GitHub (Jul 23, 2025): > Would it be possible to get a comprehensive list of endpoints that would be affected? Based on the other issue, it looks like querysets within views that use the annotate aggregation. But is this the only method that would affect the ordering? The following API endpoints appear to be affected: - /api/extras/tagged-objects/ - /api/users/tokens/
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10892