Skip to content

Commit

Permalink
Handle exceptions on request processors in incompatible plugins, and …
Browse files Browse the repository at this point in the history
…display status in Plugins page
  • Loading branch information
bctiemann committed Feb 5, 2025
1 parent 9f8b32a commit 89f1233
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions netbox/core/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_local_plugins(plugins=None):
local_plugins = {}

# Gather all locally-installed plugins
for plugin_name in registry['plugins']['installed']:
for plugin_name in settings.PLUGINS:
plugin = importlib.import_module(plugin_name)
plugin_config: PluginConfig = plugin.config
installed_version = plugin_config.version
Expand All @@ -91,15 +91,15 @@ def get_local_plugins(plugins=None):
tag_line=plugin_config.description,
description_short=plugin_config.description,
is_local=True,
is_installed=True,
is_installed=plugin_name in registry['plugins']['installed'],
installed_version=installed_version,
)

# Update catalog entries for local plugins, or add them to the list if not listed
for k, v in local_plugins.items():
if k in plugins:
plugins[k].is_local = True
plugins[k].is_installed = True
plugins[k].is_installed = k in registry['plugins']['installed']
plugins[k].installed_version = v.installed_version
else:
plugins[k] = v
Expand Down
6 changes: 5 additions & 1 deletion netbox/netbox/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import uuid
import warnings

from django.conf import settings
from django.contrib import auth, messages
Expand Down Expand Up @@ -37,7 +38,10 @@ def __call__(self, request):
# Apply all registered request processors
with ExitStack() as stack:
for request_processor in registry['request_processors']:
stack.enter_context(request_processor(request))
try:
stack.enter_context(request_processor(request))
except Exception as e:
warnings.warn(f'Failed to initialize request processor {request_processor}: {e}')
response = self.get_response(request)

# Check if language cookie should be renewed
Expand Down

0 comments on commit 89f1233

Please sign in to comment.