Preserve parent_bay during device bulk import when tags are present #699

Closed
opened 2026-04-05 17:13:35 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @bctiemann on 12/19/2025

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.

*Originally created by @bctiemann on 12/19/2025* ### 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`.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#699