Prefetch DeviceType.subdevice_role for Devices API requests #3570

Closed
opened 2025-12-29 18:29:56 +01:00 by adam · 1 comment
Owner

Originally created by @netsandbox on GitHub (Apr 14, 2020).

Environment

  • Python version: 3.6.9
  • NetBox version: 2.7.12

Proposed Functionality

Prefetch DeviceType.subdevice_role for Devices API requests (https://netbox/api/dcim/devices/).

Currently DeviceType.manufacturer is already prefetched:
ee51dae73f/netbox/dcim/api/views.py (L319-L322)

Use Case

Sometimes Devices need a special handling whether their DeviceType.subdevice_role is parent, child or None.
In our case, we want to use NetBox as Ansible inventory source, but we will not manage in Ansible Devices which DeviceType.subdevice_role is parent.

Currently we have to get first all Devices from the API, and then use the device_type.url to make another request to the API for each Device to get the subdevice_role.

If device_type.subdevice_role would be accessible in the Devices API request, we only have to do one API request.

Database Changes

None

External Dependencies

None

Originally created by @netsandbox on GitHub (Apr 14, 2020). ### Environment * Python version: 3.6.9 * NetBox version: 2.7.12 ### Proposed Functionality Prefetch `DeviceType.subdevice_role` for Devices API requests (https://netbox/api/dcim/devices/). Currently `DeviceType.manufacturer` is already prefetched: https://github.com/netbox-community/netbox/blob/ee51dae73f1fc0ad306c16f95efcfa9a5474fd81/netbox/dcim/api/views.py#L319-L322 ### Use Case Sometimes Devices need a special handling whether their DeviceType.subdevice_role is parent, child or None. In our case, we want to use NetBox as Ansible inventory source, but we will not manage in Ansible Devices which DeviceType.subdevice_role is parent. Currently we have to get first all Devices from the API, and then use the device_type.url to make another request to the API for each Device to get the subdevice_role. If device_type.subdevice_role would be accessible in the Devices API request, we only have to do one API request. ### Database Changes None ### External Dependencies None
adam closed this issue 2025-12-29 18:29:56 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 15, 2020):

Currently we have to get first all Devices from the API, and then use the device_type.url to make another request to the API for each Device to get the subdevice_role.

The same is true for any of the dozen or so other device model properties. Including them all would result in excessively large and slow responses. That's why we use minimal nested serializations of related objects, which contain the minimum amount of information necessary to display a meaningful reference to the object. This is consistent throughout the entire API.

@jeremystretch commented on GitHub (Apr 15, 2020): > Currently we have to get first all Devices from the API, and then use the device_type.url to make another request to the API for each Device to get the subdevice_role. The same is true for any of the dozen or so other device model properties. Including them all would result in excessively large and slow responses. That's why we use minimal nested serializations of related objects, which contain the minimum amount of information necessary to display a meaningful reference to the object. This is consistent throughout the entire API.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3570