1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fix handling of ProtectedError exceptions

This commit is contained in:
Jeremy Stretch
2020-07-16 13:45:02 -04:00
parent bdf41451eb
commit 1dbf776279
2 changed files with 9 additions and 24 deletions

View File

@ -345,10 +345,9 @@ class ModelViewSet(_ModelViewSet):
try:
return super().dispatch(request, *args, **kwargs)
except ProtectedError as e:
models = [
'{} ({})'.format(o, o._meta) for o in e.protected_objects.all()
]
msg = 'Unable to delete object. The following dependent objects were found: {}'.format(', '.join(models))
protected_objects = list(e.protected_objects)
msg = f'Unable to delete object. {len(protected_objects)} dependent objects were found: '
msg += ', '.join([f'{obj} ({obj.pk})' for obj in protected_objects])
logger.warning(msg)
return self.finalize_response(
request,