Skip to content

Conversation

@bctiemann
Copy link
Contributor

Fixes: #18863

Because MPTT-based models rely on an implicit hierarchical ordering behavior, the central ordering of querysets of these models as introduced in #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.

@bctiemann bctiemann requested review from a team and arthanson and removed request for a team March 11, 2025 19:06
Copy link
Collaborator

@arthanson arthanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the code is getting more complicated, can this be put into a Mixin that is included in both places so we centralize the code?

@bctiemann
Copy link
Contributor Author

Because get_queryset takes a request in one place and not the other, and because the classes both have long inheritance trees already and the MRO causes a new mixin to just make things more confusing, I ended up deciding a util function was the best place for this logic to live. Open to suggestions of better organizational ideas, but at least now the redundancy is minimized.

@bctiemann bctiemann requested a review from arthanson March 12, 2025 22:56
@arthanson arthanson merged commit 4f45328 into main Mar 13, 2025
6 checks passed
i21023 pushed a commit to i21023/netbox_certificate_management that referenced this pull request Mar 25, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 13, 2025
@jnovinger jnovinger deleted the 18863-exempt-mptt-models-from-ordering-fix branch August 20, 2025 15:52
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.

List views of self-nesting (recursive) object types are displayed incorrectly

3 participants