[PR #18867] [MERGED] Fixes: #18863 - Exempt MPTT-based models from centrally applying ordering on querysets #15461

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/18867
Author: @bctiemann
Created: 3/11/2025
Status: Merged
Merged: 3/13/2025
Merged by: @arthanson

Base: mainHead: 18863-exempt-mptt-models-from-ordering-fix


📝 Commits (2)

  • fd502d5 Exempt MPTT-based models from centrally applying ordering on querysets
  • 48f2e7f Move queryset reordering logic to a utility function, reapply_model_ordering

📊 Changes

3 files changed (+20 additions, -13 deletions)

View changed files

📝 netbox/netbox/api/viewsets/__init__.py (+2 -6)
📝 netbox/netbox/views/generic/bulk_views.py (+2 -6)
📝 netbox/utilities/query.py (+16 -1)

📄 Description

Fixes: #18863

Because MPTT-based models rely on an implicit hierarchical ordering behavior, the central ordering of querysets of these models as introduced in https://github.com/netbox-community/netbox/issues/18729 causes its own unpredictability when using list views (which should preserve the hierarchical presentation). This includes models such as Region, ContactGroup, TenantGroup, etc.

This change identifies these models through checking model._meta.local_managers and exempts them from having order_by reapplied during list views in the API and UI.


🔄 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/18867 **Author:** [@bctiemann](https://github.com/bctiemann) **Created:** 3/11/2025 **Status:** ✅ Merged **Merged:** 3/13/2025 **Merged by:** [@arthanson](https://github.com/arthanson) **Base:** `main` ← **Head:** `18863-exempt-mptt-models-from-ordering-fix` --- ### 📝 Commits (2) - [`fd502d5`](https://github.com/netbox-community/netbox/commit/fd502d553cb4ea4935723ebcc556015dc3eb4a11) Exempt MPTT-based models from centrally applying ordering on querysets - [`48f2e7f`](https://github.com/netbox-community/netbox/commit/48f2e7f1f5df11f4f0a7086e24f3a4d57f134fb7) Move queryset reordering logic to a utility function, reapply_model_ordering ### 📊 Changes **3 files changed** (+20 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `netbox/netbox/api/viewsets/__init__.py` (+2 -6) 📝 `netbox/netbox/views/generic/bulk_views.py` (+2 -6) 📝 `netbox/utilities/query.py` (+16 -1) </details> ### 📄 Description ### Fixes: #18863 Because MPTT-based models rely on an implicit hierarchical ordering behavior, the central ordering of querysets of these models as introduced in https://github.com/netbox-community/netbox/issues/18729 causes its own unpredictability when using list views (which should preserve the hierarchical presentation). This includes models such as `Region`, `ContactGroup`, `TenantGroup`, etc. This change identifies these models through checking `model._meta.local_managers` and exempts them from having `order_by` reapplied during list views in the API and UI. --- <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:22:04 +01:00
adam closed this issue 2025-12-30 00:22:05 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15461