[PR #16553] [MERGED] Fixes 16536 - Fix filtering of device component by device role #14863

Closed
opened 2025-12-29 23:27:10 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/16553
Author: @Alef-Burzmali
Created: 6/13/2024
Status: Merged
Merged: 7/12/2024
Merged by: @jeremystretch

Base: developHead: 16536-device-component-filtering


📝 Commits (2)

  • 21cc1aa Fixes 16536 - Fix filtering of device component by device role
  • 0a32800 Update tests for DeviceComponentFilterSet

📊 Changes

2 files changed (+12 additions, -5 deletions)

View changed files

📝 netbox/dcim/filtersets.py (+2 -2)
📝 netbox/dcim/tests/test_filtersets.py (+10 -3)

📄 Description

Fixes: #16536

Fix the filtering of device components by device role by aligning the name of the fields from the DeviceComponentFilterForm and the DeviceComponentFilterSet.

I saw two solutions to implement the fix:

  1. Rename the fields in the DeviceComponentFilterSet to device_role_id and device_role (that's the one I've implemented)
  2. Rename the field in the DeviceComponentFilterForm to role_id but create an exception for InventoryItemFilterSet and InventoryItemFilterForm, which already have a field named role for the InventoryItemRole

I've chosen solution 1 because:

  • We are not filtering according to the component's role but according to its parent device's role, so device_role makes more sense as role could be confused with the role of the component.
  • It avoids creating an exception for InventoryItemFilterSet, which would have its role field override the role field from DeviceComponentFilterSet, and would have needed a device_role field or equivalent to preserve the feature. The role filter of DeviceComponent would have a different meaning between an Interface or a InventoryItem, which would have been more confusing.
  • While the release note for 4.0 clearly states in breaking changes that the device_role field of devices has been removed after a depreciation period, there are no mentions of DeviceComponent in the notes or in #13342, so it may have been an undocumented or unintended change
  • There is no equivalent filtering on VMInterface, it's not possible to filter them by their VM's role at the moment, so the reason behind the renaming of "device_role" to "role" is not currently present for DeviceComponent. However, if this feature is added, a more neutral field name such as "parent_role" or "parent_object_role" could be used instead.
  • It's the least amount of changes required for this fix. Solution 2 would have required modifying InventoryItemFilterSet, InventoryItemFilterForm, DeviceComponentFilterForm and the fieldsets of all inheriting FilterForms.

However, solution 1 also changes the API to filter the device components by roles. This was an undocumented change in 4.0, so maybe that's acceptable.

Please let me know if you agree with that approach or if you prefer another solution.


🔄 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/16553 **Author:** [@Alef-Burzmali](https://github.com/Alef-Burzmali) **Created:** 6/13/2024 **Status:** ✅ Merged **Merged:** 7/12/2024 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `16536-device-component-filtering` --- ### 📝 Commits (2) - [`21cc1aa`](https://github.com/netbox-community/netbox/commit/21cc1aa28943bbf148497ea18b859592501ac47a) Fixes 16536 - Fix filtering of device component by device role - [`0a32800`](https://github.com/netbox-community/netbox/commit/0a32800d488697d29d9777f62a03878e157a132a) Update tests for DeviceComponentFilterSet ### 📊 Changes **2 files changed** (+12 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/filtersets.py` (+2 -2) 📝 `netbox/dcim/tests/test_filtersets.py` (+10 -3) </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: #16536 <!-- Please include a summary of the proposed changes below. --> Fix the filtering of device components by device role by aligning the name of the fields from the DeviceComponentFilterForm and the DeviceComponentFilterSet. I saw two solutions to implement the fix: 1. Rename the fields in the DeviceComponentFilterSet to `device_role_id` and `device_role` (that's the one I've implemented) 2. Rename the field in the DeviceComponentFilterForm to `role_id` but create an exception for InventoryItemFilterSet and InventoryItemFilterForm, which already have a field named `role` for the InventoryItemRole I've chosen solution 1 because: * We are not filtering according to the component's role but according to its parent device's role, so `device_role` makes more sense as `role` could be confused with the role of the component. * It avoids creating an exception for InventoryItemFilterSet, which would have its `role` field override the role field from DeviceComponentFilterSet, and would have needed a `device_role` field or equivalent to preserve the feature. The role filter of DeviceComponent would have a different meaning between an Interface or a InventoryItem, which would have been more confusing. * While the release note for 4.0 clearly states in breaking changes that the device_role field of devices has been removed after a depreciation period, there are no mentions of DeviceComponent in the notes or in #13342, so it may have been an undocumented or unintended change * There is no equivalent filtering on VMInterface, it's not possible to filter them by their VM's role at the moment, so the reason behind the renaming of "device_role" to "role" is not currently present for DeviceComponent. However, if this feature is added, a more neutral field name such as "parent_role" or "parent_object_role" could be used instead. * It's the least amount of changes required for this fix. Solution 2 would have required modifying InventoryItemFilterSet, InventoryItemFilterForm, DeviceComponentFilterForm and the fieldsets of all inheriting FilterForms. However, solution 1 also changes the API to filter the device components by roles. This was an undocumented change in 4.0, so maybe that's acceptable. Please let me know if you agree with that approach or if you prefer another solution. --- <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-29 23:27:10 +01:00
adam closed this issue 2025-12-29 23:27:10 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14863