[PR #19943] [MERGED] Fixes #18900: raise QuerySetNotOrdered exception when trying to paginate unordered API querysets #15769

Closed
opened 2025-12-30 00:23:56 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/19943
Author: @jnovinger
Created: 7/23/2025
Status: Merged
Merged: 7/29/2025
Merged by: @jnovinger

Base: mainHead: 18900-paginator-should-not-paginate-unsorted-queryset


📝 Commits (6)

  • 8c82092 Fixes #18900: introduce/raise QuerySetNotOrdered exception
  • 75c726e Don't try to reapply ordering if ordering is already present
  • 6966c7a Add ordering for failing tagged-objects list API endpoint
  • 8e39481 Add default Token ordering behavior
  • 7fa81f1 Adds basic tests for raising QuerySetNotOrdered
  • 808db8c Note why ordering is not applied in TaggedItem.Meta

📊 Changes

8 files changed (+80 additions, -1 deletions)

View changed files

📝 netbox/extras/api/views.py (+3 -1)
📝 netbox/extras/models/tags.py (+3 -0)
📝 netbox/netbox/api/exceptions.py (+4 -0)
📝 netbox/netbox/api/pagination.py (+7 -0)
📝 netbox/netbox/tests/test_api.py (+42 -0)
netbox/users/migrations/0010_add_token_meta_ordering.py (+17 -0)
📝 netbox/users/models/tokens.py (+1 -0)
📝 netbox/utilities/query.py (+3 -0)

📄 Description

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 #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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/19943 **Author:** [@jnovinger](https://github.com/jnovinger) **Created:** 7/23/2025 **Status:** ✅ Merged **Merged:** 7/29/2025 **Merged by:** [@jnovinger](https://github.com/jnovinger) **Base:** `main` ← **Head:** `18900-paginator-should-not-paginate-unsorted-queryset` --- ### 📝 Commits (6) - [`8c82092`](https://github.com/netbox-community/netbox/commit/8c820924fb8fcc007a8355a3cd2a487c5bae58de) Fixes #18900: introduce/raise QuerySetNotOrdered exception - [`75c726e`](https://github.com/netbox-community/netbox/commit/75c726e86d8c490852b2bb3728f3d6606df3f762) Don't try to reapply ordering if ordering is already present - [`6966c7a`](https://github.com/netbox-community/netbox/commit/6966c7ac2356bf7c349dd86ce0b00b39c1472f39) Add ordering for failing tagged-objects list API endpoint - [`8e39481`](https://github.com/netbox-community/netbox/commit/8e39481c6b2791ac1b66b6c050deff14aa05720c) Add default Token ordering behavior - [`7fa81f1`](https://github.com/netbox-community/netbox/commit/7fa81f1498a5d04b9aee519c65afffb1026388db) Adds basic tests for raising QuerySetNotOrdered - [`808db8c`](https://github.com/netbox-community/netbox/commit/808db8c8e855de0d6a5b4c7676d8e7f98fd7da58) Note why ordering is not applied in TaggedItem.Meta ### 📊 Changes **8 files changed** (+80 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `netbox/extras/api/views.py` (+3 -1) 📝 `netbox/extras/models/tags.py` (+3 -0) 📝 `netbox/netbox/api/exceptions.py` (+4 -0) 📝 `netbox/netbox/api/pagination.py` (+7 -0) 📝 `netbox/netbox/tests/test_api.py` (+42 -0) ➕ `netbox/users/migrations/0010_add_token_meta_ordering.py` (+17 -0) 📝 `netbox/users/models/tokens.py` (+1 -0) 📝 `netbox/utilities/query.py` (+3 -0) </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be approved and assigned prior to opening a pull request. This helps avoid waste time and effort on a proposed change that we might not be able to accept. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ISSUE WHICH HAS BEEN ASSIGNED TO YOU, IT WILL BE CLOSED AUTOMATICALLY. Please specify your assigned issue number on the line below. --> ### 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 #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. <!-- Please include a summary of the proposed changes below. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:23:56 +01:00
adam closed this issue 2025-12-30 00:23:57 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15769