diff --git a/netbox/dcim/forms/bulk_import.py b/netbox/dcim/forms/bulk_import.py index f0fd9bf86..ec6ea145d 100644 --- a/netbox/dcim/forms/bulk_import.py +++ b/netbox/dcim/forms/bulk_import.py @@ -576,7 +576,7 @@ class PowerOutletCSVForm(NetBoxModelCSVForm): super().__init__(*args, **kwargs) # Limit PowerPort choices to those belonging to this device (or VC master) - if self.is_bound: + if self.is_bound and 'device' in self.data: try: device = self.fields['device'].to_python(self.data['device']) except forms.ValidationError: @@ -711,7 +711,7 @@ class FrontPortCSVForm(NetBoxModelCSVForm): super().__init__(*args, **kwargs) # Limit RearPort choices to those belonging to this device (or VC master) - if self.is_bound: + if self.is_bound and 'device' in self.data: try: device = self.fields['device'].to_python(self.data['device']) except forms.ValidationError: @@ -782,7 +782,7 @@ class DeviceBayCSVForm(NetBoxModelCSVForm): super().__init__(*args, **kwargs) # Limit installed device choices to devices of the correct type and location - if self.is_bound: + if self.is_bound and 'device' in self.data: try: device = self.fields['device'].to_python(self.data['device']) except forms.ValidationError: diff --git a/netbox/dcim/tests/test_views.py b/netbox/dcim/tests/test_views.py index 9319d0afb..35c7e60e6 100644 --- a/netbox/dcim/tests/test_views.py +++ b/netbox/dcim/tests/test_views.py @@ -394,7 +394,7 @@ class RackTestCase(ViewTestCases.PrimaryObjectViewTestCase): ) cls.csv_update_data = ( - "name, status", + "name,status", f"Rack 7,{RackStatusChoices.STATUS_DEPRECATED}", f"Rack 8,{RackStatusChoices.STATUS_DEPRECATED}", f"Rack 9,{RackStatusChoices.STATUS_DEPRECATED}", diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index 6a9dd91ac..3aead6151 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -298,13 +298,13 @@ class IPAddressCSVForm(NetBoxModelCSVForm): def save(self, *args, **kwargs): # Set interface assignment - if self.cleaned_data['interface']: + if self.cleaned_data.get('interface'): self.instance.assigned_object = self.cleaned_data['interface'] ipaddress = super().save(*args, **kwargs) # Set as primary for device/VM - if self.cleaned_data['is_primary']: + if self.cleaned_data.get('is_primary'): parent = self.cleaned_data['device'] or self.cleaned_data['virtual_machine'] if self.instance.address.version == 4: parent.primary_ip4 = ipaddress diff --git a/netbox/utilities/testing/views.py b/netbox/utilities/testing/views.py index 4f0d99a26..843509f7a 100644 --- a/netbox/utilities/testing/views.py +++ b/netbox/utilities/testing/views.py @@ -615,7 +615,7 @@ class ViewTestCases: obj_perm.object_types.add(ContentType.objects.get_for_model(self.model)) self.assertHttpStatus(self.client.post(self._get_url('import'), data), 200) - start_id = self._get_queryset().first().id + start_id = self._get_queryset().order_by('id').first().id # Now try update the data array, csv_data = self._get_update_csv_data(start_id)