Skip to content

Conversation

@bctiemann
Copy link
Contributor

@bctiemann bctiemann commented Mar 4, 2025

Fixes: #18729

Adding .annotate to querysets has the effect of negating the ordering setting defined on models. Thus when we put annotations/groupings on the queryset on various list views (for example ClusterViewSet in the API, or ProviderListView in the UI), i.e. to count related objects to show in columns or fields, the model-level sorting is lost and records are returned in an unpredictable order, leading to repetitions and misses by paginating clients.

This change adds a get_queryset override to each of the relevant list view classes, to take the specified queryset and reapply the ordering fields that are defined in the queryset's model class. This occurs centrally and uniformly, thus not requiring many changes throughout the system. It also does not interfere with custom sorting as specified via query params (e.g. &ordering=name).

@bctiemann bctiemann requested review from a team and arthanson and removed request for a team March 4, 2025 19:50
@arthanson arthanson merged commit 6efc568 into main Mar 5, 2025
6 checks passed
@jeremystretch jeremystretch deleted the 18729-apply-model-ordering-on-list-views branch March 6, 2025 16:35
bctiemann added a commit that referenced this pull request Mar 6, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 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.

Netbox API returns duplicate resources during paging with offset

3 participants