diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index b18ecdd5b64..a89bafc1a19 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -2122,6 +2122,17 @@ class DeviceBulkRenameView(generic.BulkRenameView): filterset = filtersets.DeviceFilterSet table = tables.DeviceTable + def _rename_objects(self, form, selected_objects): + # Check devices for any unnamed devices and enforce requirements on the renaming of devices + for obj in selected_objects: + if not form.cleaned_data['use_regex'] and not obj.name: + from django.core.exceptions import ValidationError + raise ValidationError({ + 'use_regex': 'You must use regex to rename a unnamed device and must pass device uniqueness checks' + }) + + super()._rename_objects(form, selected_objects) + @register_model_view(Device, 'contacts') class DeviceContactsView(ObjectContactsView): diff --git a/netbox/netbox/views/generic/bulk_views.py b/netbox/netbox/views/generic/bulk_views.py index bdc9a7152a5..8270507b5fb 100644 --- a/netbox/netbox/views/generic/bulk_views.py +++ b/netbox/netbox/views/generic/bulk_views.py @@ -776,6 +776,14 @@ def post(self, request): ) return redirect(self.get_return_url(request)) + except IntegrityError as e: + messages.error(self.request, ", ".join(e.args)) + clear_events.send(sender=self) + + except ValidationError as e: + messages.error(self.request, ", ".join(e.messages)) + clear_events.send(sender=self) + except (AbortRequest, PermissionsViolation) as e: logger.debug(e.message) form.add_error(None, e.message)