netbox icon indicating copy to clipboard operation
netbox copied to clipboard

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

Open jeremystretch opened this issue 9 months ago • 2 comments

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.

jeremystretch avatar Mar 13 '25 19:03 jeremystretch

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 avatar Mar 14 '25 14:03 atownson

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] avatar Jun 13 '25 04:06 github-actions[bot]

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 avatar Jul 23 '25 11:07 jnovinger