Open
Description
Deployment Type
Self-hosted
NetBox Version
tested and verified on v3.7.2, but I see the problem exists even in the latest NetBox
Python Version
3.10
Steps to Reproduce
- Create a plugin with dot(s) in the name (common for namespaced packages)
- Add it to
configuration.py
PLUGINS = [
'company.netbox_plugins.custom_metrics',
]
- List installed plugins on UI (http://localhost:8000/admin/plugins/installed-plugins/)
- Observer the error:
Internal Server Error: /admin/plugins/installed-plugins/
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/django/apps/registry.py", line 158, in get_app_config
return self.app_configs[app_label]
KeyError: 'company.netbox_plugins.custom_metrics'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.8/dist-packages/django/contrib/auth/decorators.py", line 23, in _wrapper_view
return view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/django/views/generic/base.py", line 104, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/django/views/generic/base.py", line 143, in dispatch
return handler(request, *args, **kwargs)
File "/opt/netbox/netbox/plugins/views.py", line 20, in get
plugins = [apps.get_app_config(plugin) for plugin in settings.PLUGINS]
File "/opt/netbox/netbox/plugins/views.py", line 20, in <listcomp>
plugins = [apps.get_app_config(plugin) for plugin in settings.PLUGINS]
File "/usr/local/lib/python3.8/dist-packages/django/apps/registry.py", line 165, in get_app_config
raise LookupError(message)
LookupError: No installed app with label 'company.netbox_plugins.custom_metrics'. Did you mean 'custom_metrics'?
"GET /admin/plugins/installed-plugins/ HTTP/1.1" 500 119462
Expected Behavior
No error should occur
Observed Behavior
There is no item in apps.get_app_configs()
with key being equal to plugin name supplied in configuration. What's actually happens is that django, in AppConfig is using app_name.rpartition(".")[2]
as default label, in django/apps/config.py, and then in populate, the label is used as the key for app_configs, in django/apps/registry.py
In netbox/plugins/views.py, there is
[apps.get_app_config(plugin)) for plugin in settings.PLUGINS]
in two places and this leads to the error.
I haven't tried it yet, but this probably needs to be:
[apps.get_app_config(plugin.rpartition(".")[2])) for plugin in settings.PLUGINS]