[PR #21006] Fixes #20320: Include parent PK in BulkEdit context for child objects #16118

Open
opened 2025-12-30 00:25:54 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/21006
Author: @pheus
Created: 12/18/2025
Status: 🔄 Open

Base: mainHead: 20320-include-parent-pk-in-bulkedit-context


📝 Commits (1)

  • 026add9 feat(object_actions): Include parent PK in BulkEdit context

📊 Changes

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

View changed files

📝 netbox/netbox/object_actions.py (+16 -0)
📝 netbox/netbox/tests/test_object_actions.py (+32 -5)

📄 Description

Fixes: #20320

This PR addresses the issue where the “Related Interfaces” selectors (Parent/Bridge/LAG) are disabled when bulk-editing interfaces from an object child view (e.g. device → interfaces) in v4.4.0.

Summary / Rationale

When bulk actions are invoked from an object child view (e.g. /dcim/devices/<pk>/interfaces/), the bulk edit action URL no longer carries the parent-scoping query parameter (e.g. device=<pk>). Without that context, the bulk edit form can’t scope/populate the related-interface fields, leaving them grayed out.

Proposed Changes

  • Enhance BulkEdit.get_context() to detect the “child view” case (presence of a parent object in the template context).
  • When applicable, inject the parent object’s primary key into the bulk edit action URL parameters (e.g. device=<parent.pk> / device_type=<parent.pk>), while preserving any existing request.GET parameters (and return_url when present).
  • Only add the parameter when it’s not already provided, to avoid altering behavior on global list views.

Tests Added

  • Added a unit test to confirm the parent object's PK is included in url_params when rendering a bulk action in a child-object context:
    • test_bulk_edit_get_context_child_object creates a DeviceType parent and verifies BulkEdit.get_context(context, Device) injects device_type=<parent.pk> into url_params when the template context includes object=<DeviceType>.
  • Also adjusted a plugin URL test to ensure the @skipIf decorator behaves correctly:
    • Moved the import of the dummy plugin model inside test_get_url_plugin_model so the module import doesn’t occur before the @skipIf condition is evaluated.

Notes / Open Question

I’m not 100% certain this is the preferred place to implement the fix (action context vs. view/template), but this approach keeps the change small and avoids duplicating templates.

How To Test

  1. Go to a device → Interfaces tab.
  2. Select multiple interfaces.
  3. Click Edit Selected.
  4. Confirm the Parent/Bridge/LAG fields are enabled and show relevant interface choices.
  5. Confirm bulk edit from the global Interfaces list behaves as before (no unintended scoping).
  6. Run the test suite (including plugin tests when netbox.tests.dummy_plugin is enabled) and confirm all tests pass.

🔄 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/21006 **Author:** [@pheus](https://github.com/pheus) **Created:** 12/18/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `20320-include-parent-pk-in-bulkedit-context` --- ### 📝 Commits (1) - [`026add9`](https://github.com/netbox-community/netbox/commit/026add9c334e70e5a26adf27242c9d60406f9975) feat(object_actions): Include parent PK in BulkEdit context ### 📊 Changes **2 files changed** (+48 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `netbox/netbox/object_actions.py` (+16 -0) 📝 `netbox/netbox/tests/test_object_actions.py` (+32 -5) </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: #20320 <!-- Please include a summary of the proposed changes below. --> This PR addresses the issue where the “Related Interfaces” selectors (Parent/Bridge/LAG) are disabled when bulk-editing interfaces from an object child view (e.g. device → interfaces) in v4.4.0. #### Summary / Rationale When bulk actions are invoked from an object child view (e.g. `/dcim/devices/<pk>/interfaces/`), the bulk edit action URL no longer carries the parent-scoping query parameter (e.g. `device=<pk>`). Without that context, the bulk edit form can’t scope/populate the related-interface fields, leaving them grayed out. #### Proposed Changes - Enhance `BulkEdit.get_context()` to detect the “child view” case (presence of a parent `object` in the template context). - When applicable, inject the parent object’s primary key into the bulk edit action URL parameters (e.g. `device=<parent.pk>` / `device_type=<parent.pk>`), while preserving any existing `request.GET` parameters (and `return_url` when present). - Only add the parameter when it’s not already provided, to avoid altering behavior on global list views. #### Tests Added - Added a unit test to confirm the parent object's PK is included in `url_params` when rendering a bulk action in a child-object context: - `test_bulk_edit_get_context_child_object` creates a `DeviceType` parent and verifies `BulkEdit.get_context(context, Device)` injects `device_type=<parent.pk>` into `url_params` when the template context includes `object=<DeviceType>`. - Also adjusted a plugin URL test to ensure the `@skipIf` decorator behaves correctly: - Moved the import of the dummy plugin model inside `test_get_url_plugin_model` so the module import doesn’t occur before the `@skipIf` condition is evaluated. #### Notes / Open Question I’m not 100% certain this is the preferred place to implement the fix (action context vs. view/template), but this approach keeps the change small and avoids duplicating templates. #### How To Test 1. Go to a device → Interfaces tab. 2. Select multiple interfaces. 3. Click **Edit Selected**. 4. Confirm the Parent/Bridge/LAG fields are enabled and show relevant interface choices. 5. Confirm bulk edit from the global Interfaces list behaves as before (no unintended scoping). 6. Run the test suite (including plugin tests when `netbox.tests.dummy_plugin` is enabled) and confirm all tests pass. --- <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:25:54 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#16118