LookupError at /admin/plugins/installed-plugins/ when using plugins with dots in their name #10793

Closed
opened 2025-12-29 21:35:59 +01:00 by adam · 2 comments
Owner

Originally created by @petrovicboban on GitHub (Feb 21, 2025).

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

  1. Create a plugin with dot(s) in the name (common for namespaced packages)
  2. Add it to configuration.py
PLUGINS = [
    'company.netbox_plugins.custom_metrics',
]
  1. List installed plugins on UI (http://localhost:8000/admin/plugins/installed-plugins/)
  2. 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]
Originally created by @petrovicboban on GitHub (Feb 21, 2025). ### 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 1. Create a plugin with dot(s) in the name (common for namespaced packages) 2. Add it to `configuration.py` ``` PLUGINS = [ 'company.netbox_plugins.custom_metrics', ] ``` 3. List installed plugins on UI (http://localhost:8000/admin/plugins/installed-plugins/) 4. 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](https://github.com/django/django/blob/87c5de3b7f2316aa17353d74f54e6ff19013d049/django/apps/config.py#L34), and then in populate, the label is used as the key for app_configs, in [django/apps/registry.py ](https://github.com/django/django/blob/87c5de3b7f2316aa17353d74f54e6ff19013d049/django/apps/registry.py#L98) In [netbox/plugins/views.py](https://github.com/netbox-community/netbox/blob/main/netbox/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] ```
adam added the type: bugstatus: needs ownerpending closureseverity: low labels 2025-12-29 21:35:59 +01:00
adam closed this issue 2025-12-29 21:36:00 +01:00
Author
Owner

@github-actions[bot] commented on GitHub (Aug 28, 2025):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Aug 28, 2025): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/main/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (Sep 28, 2025):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (Sep 28, 2025): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10793