From 7a622e9b09a60f254a28cb4738573cbecd5ccc79 Mon Sep 17 00:00:00 2001 From: pl0xym0r <148605740+pl0xym0r@users.noreply.github.com> Date: Wed, 22 Oct 2025 12:43:21 +0000 Subject: [PATCH] Closes #20459 : clean is_oob and is_primary on bulk_import --- netbox/ipam/forms/bulk_import.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index c0aa4346190..8cef521ea94 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -369,6 +369,20 @@ def __init__(self, data=None, *args, **kwargs): **{f"virtual_machine__{self.fields['virtual_machine'].to_field_name}": data['virtual_machine']} ) + def clean_is_primary(self): + # Make sure is_primary is None when it's not included in the uploaded data + if 'is_primary' not in self.data: + return None + else: + return self.cleaned_data['is_primary'] + + def clean_is_oob(self): + # Make sure is_oob is None when it's not included in the uploaded data + if 'is_oob' not in self.data: + return None + else: + return self.cleaned_data['is_oob'] + def clean(self): super().clean() @@ -411,18 +425,18 @@ def save(self, *args, **kwargs): ipaddress = super().save(*args, **kwargs) # Set as primary for device/VM - if self.cleaned_data.get('is_primary'): + if self.cleaned_data.get('is_primary') is not None: parent = self.cleaned_data.get('device') or self.cleaned_data.get('virtual_machine') if self.instance.address.version == 4: - parent.primary_ip4 = ipaddress + parent.primary_ip4 = ipaddress if self.cleaned_data.get('is_primary') else None elif self.instance.address.version == 6: - parent.primary_ip6 = ipaddress + parent.primary_ip6 = ipaddress if self.cleaned_data.get('is_primary') else None parent.save() # Set as OOB for device - if self.cleaned_data.get('is_oob'): + if self.cleaned_data.get('is_oob') is not None: parent = self.cleaned_data.get('device') - parent.oob_ip = ipaddress + parent.oob_ip = ipaddress if self.cleaned_data.get('is_oob') else None parent.save() return ipaddress