From 28facca29189d3af9336b2dc24e66312e8334260 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 29 May 2019 10:33:29 -0400 Subject: [PATCH] Changelog & grammar tweak for #3211 --- CHANGELOG.md | 1 + netbox/utilities/api.py | 7 ++----- netbox/utilities/middleware.py | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d6fbbd68..1fc7dbebd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * [#3150](https://github.com/digitalocean/netbox/issues/3150) - Fix formatting of cable length during cable trace * [#3184](https://github.com/digitalocean/netbox/issues/3184) - Correctly display color block for white cables * [#3190](https://github.com/digitalocean/netbox/issues/3190) - Fix custom field rendering for Jinja2 export templates +* [#3211](https://github.com/digitalocean/netbox/issues/3211) - Fix error handling when attempting to delete a protected object via API * [#3223](https://github.com/digitalocean/netbox/issues/3223) - Fix filtering devices by "has power outlets" --- diff --git a/netbox/utilities/api.py b/netbox/utilities/api.py index 9960fbe42..74108fbc9 100644 --- a/netbox/utilities/api.py +++ b/netbox/utilities/api.py @@ -252,11 +252,8 @@ class ModelViewSet(_ModelViewSet): try: return super().dispatch(request, *args, **kwargs) except ProtectedError as e: - models = '\n'.join( - '- {} ({})'.format(o, o._meta) - for o in e.protected_objects.all() - ) - msg = 'You tried deleting a model that is protected by:\n{}'.format(models) + 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)) return self.finalize_response( request, Response({'detail': msg}, status=409), diff --git a/netbox/utilities/middleware.py b/netbox/utilities/middleware.py index b2065543a..4e321ab19 100644 --- a/netbox/utilities/middleware.py +++ b/netbox/utilities/middleware.py @@ -70,6 +70,7 @@ class ExceptionHandlingMiddleware(object): custom_template = 'exceptions/import_error.html' elif isinstance(exception, PermissionError): custom_template = 'exceptions/permission_error.html' + # Return a custom error message, or fall back to Django's default 500 error handling if custom_template: return server_error(request, template_name=custom_template)