[PR #21019] [MERGED] Preserve parent_bay during device bulk import when tags are present #16122

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/21019
Author: @bctiemann
Created: 12/19/2025
Status: Merged
Merged: 12/20/2025
Merged by: @jnovinger

Base: mainHead: 20114-bulk-import-device-preserve-parent_bay


📝 Commits (1)

  • ff97ab9 Preserve parent_bay during device bulk import when tags are present

📊 Changes

1 file changed (+3 additions, -2 deletions)

View changed files

📝 netbox/dcim/views.py (+3 -2)

📄 Description

Fixes: #20114

When tags are present, the _save_m2m method of BaseModelForm causes the instance to be forcibly saved via f.save_form_data(self.instance, cleaned_data[f.name]). However, because we detect the presence of a device's parent device bay by stashing it on the instance prior to save:

ff97ab96c7/netbox/dcim/forms/bulk_import.py (L730-L732)

The _save_m2m behavior normally leaves parent_bay alone, but if tags are present, this intermediary save_form_data has the effect of regenerating the saved obj and clearing out the synthetic parent_bay attribute.

This fix ensures parent_bay survives this process by pulling it from the object_form.instance prior to calling the save chain, rather than assuming the result of save will still have parent_bay.


🔄 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/21019 **Author:** [@bctiemann](https://github.com/bctiemann) **Created:** 12/19/2025 **Status:** ✅ Merged **Merged:** 12/20/2025 **Merged by:** [@jnovinger](https://github.com/jnovinger) **Base:** `main` ← **Head:** `20114-bulk-import-device-preserve-parent_bay` --- ### 📝 Commits (1) - [`ff97ab9`](https://github.com/netbox-community/netbox/commit/ff97ab96c7e075571d2e33f0ac06cd741cfd4a82) Preserve parent_bay during device bulk import when tags are present ### 📊 Changes **1 file changed** (+3 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/views.py` (+3 -2) </details> ### 📄 Description ### Fixes: #20114 When tags are present, the `_save_m2m` method of `BaseModelForm` causes the instance to be forcibly saved via `f.save_form_data(self.instance, cleaned_data[f.name])`. However, because we detect the presence of a device's parent device bay by stashing it on the instance prior to `save`: https://github.com/netbox-community/netbox/blob/ff97ab96c7e075571d2e33f0ac06cd741cfd4a82/netbox/dcim/forms/bulk_import.py#L730-L732 The `_save_m2m` behavior normally leaves `parent_bay` alone, but if tags are present, this intermediary `save_form_data` has the effect of regenerating the saved `obj` and clearing out the synthetic `parent_bay` attribute. This fix ensures `parent_bay` survives this process by pulling it from the `object_form.instance` prior to calling the `save` chain, rather than assuming the result of `save` will still have `parent_bay`. --- <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:55 +01:00
adam closed this issue 2025-12-30 00:25:56 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#16122