Add child object counts to API serializers for organizational objects #1531

Closed
opened 2025-12-29 16:32:44 +01:00 by adam · 0 comments
Owner

Originally created by @jeremystretch on GitHub (Feb 6, 2018).

Issue type

[x] Feature request
[ ] Bug report
[ ] Documentation

Environment

  • Python version: 3.5.2
  • NetBox version: 2.2.9

Description

Currently, the API serializers for objects generally do not include any information about child objects. This was an intentional decision made early on in NetBox's development to avoid introducing a potential performance issue. However, it would be beneficial to include aggregate child object counts for certain organizational objects. For instance, the rack group serializer should include a count of racks belonging to each group.

For most objects, this should be fairly straightforward, and we can leverage query annotations to include a count of child objects. Some objects, however, have multiple types of children, in which case distinct annotations introduce a significant performance penalty. Individual database queries per parent object might be preferable in these cases.

Originally created by @jeremystretch on GitHub (Feb 6, 2018). ### Issue type [x] Feature request <!-- An enhancement of existing functionality --> [ ] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> ### Environment * Python version: 3.5.2 * NetBox version: 2.2.9 ### Description Currently, the API serializers for objects generally do not include any information about child objects. This was an intentional decision made early on in NetBox's development to avoid introducing a potential performance issue. However, it would be beneficial to include aggregate child object counts for certain organizational objects. For instance, the rack group serializer should include a count of racks belonging to each group. For most objects, this should be fairly straightforward, and we can leverage [query annotations](https://docs.djangoproject.com/en/1.11/ref/models/querysets/#annotate) to include a count of child objects. Some objects, however, have multiple types of children, in which case distinct annotations introduce a significant performance penalty. Individual database queries per parent object might be preferable in these cases.
adam added the status: acceptedtype: feature labels 2025-12-29 16:32:44 +01:00
adam closed this issue 2025-12-29 16:32:44 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1531