Skip to content

Conversation

jnovinger
Copy link
Member

Fixes: #18900

  • Introduce and raise QuerySetNotOrdered exception when an API endpoint tries to paginate a queryset instance that has not been ordered or has lost its ordering (see Netbox API returns duplicate resources during paging with offset #18729).
  • Modify reapply_model_ordering() to not reapply default orderings if queryset is already ordered.
  • Provide default ordering behavior for users.Token model
  • Provide default ordering behavior for Tagged Item API list endpoint (/api/extras/tagged-objects/). See specific commit message for reasoning of this approach.

Defines a new exception, `QuerySetNotOrdered`, and raises it in
`OptionalLimitOffsetPagination.paginate_queryset` in the right
conditions:
- the iterable to be paginated is a QuerySet isinstance
- the `queryset.ordered` flag is not truthy
I chose to implement this here for TaggedItemViewSet, rather than on the
model, because any meaningful ordering is going to be done on the
related Tag instance and I didn't want to introduce potential, not well
understood side-effects by applying a model-wide ordering via a related
model field.
@jnovinger jnovinger requested review from a team and bctiemann and removed request for a team July 23, 2025 17:37
@jnovinger jnovinger marked this pull request as draft July 23, 2025 20:54
@jnovinger jnovinger marked this pull request as ready for review July 29, 2025 16:18
bctiemann
bctiemann previously approved these changes Jul 29, 2025
@jnovinger jnovinger requested a review from bctiemann July 29, 2025 16:36
@jnovinger jnovinger merged commit c736ce3 into main Jul 29, 2025
10 checks passed
@jnovinger jnovinger deleted the 18900-paginator-should-not-paginate-unsorted-queryset branch July 29, 2025 16:49
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants