Fixes #20320: Include parent PK in BulkEdit context for child objects #21006
+48
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
BulkEdit.get_context()to detect the “child view” case (presence of a parentobjectin the template context).device=<parent.pk>/device_type=<parent.pk>), while preserving any existingrequest.GETparameters (andreturn_urlwhen present).Tests Added
url_paramswhen rendering a bulk action in a child-object context:test_bulk_edit_get_context_child_objectcreates aDeviceTypeparent and verifiesBulkEdit.get_context(context, Device)injectsdevice_type=<parent.pk>intourl_paramswhen the template context includesobject=<DeviceType>.@skipIfdecorator behaves correctly:test_get_url_plugin_modelso the module import doesn’t occur before the@skipIfcondition 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
netbox.tests.dummy_pluginis enabled) and confirm all tests pass.