From aeef559c0ba149cda2f961d0e2ea3d0cf38f0b16 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Thu, 2 Apr 2026 11:08:04 -0400 Subject: [PATCH] Catch exceptions raised when rendering embedded plugin content --- netbox/templates/ui/exception.html | 12 ++++++++++++ netbox/utilities/templatetags/plugins.py | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 netbox/templates/ui/exception.html diff --git a/netbox/templates/ui/exception.html b/netbox/templates/ui/exception.html new file mode 100644 index 000000000..a777b0b5e --- /dev/null +++ b/netbox/templates/ui/exception.html @@ -0,0 +1,12 @@ +{% load i18n %} + diff --git a/netbox/utilities/templatetags/plugins.py b/netbox/utilities/templatetags/plugins.py index 40e6b8196..c3157d119 100644 --- a/netbox/utilities/templatetags/plugins.py +++ b/netbox/utilities/templatetags/plugins.py @@ -1,5 +1,6 @@ from django import template as template_ from django.conf import settings +from django.template.loader import render_to_string from django.utils.safestring import mark_safe from netbox.plugins import PluginTemplateExtension @@ -38,8 +39,11 @@ def _get_registered_content(obj, method, template_context): context['config'] = settings.PLUGINS_CONFIG.get(plugin_name, {}) # Call the method to render content - instance = template_extension(context) - content = getattr(instance, method)() + try: + instance = template_extension(context) + content = getattr(instance, method)() + except Exception as e: + content = render_to_string('ui/exception.html', {'plugin': plugin_name, 'exception': repr(e)}) html += content return mark_safe(html)