-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox version
v3.4.0
Feature type
Change to existing functionality
Proposed functionality
This has been requested before, see #4628. I'm currently writing my first plugin and just spent about a day trying to figure out why it won't get loaded. No matter how far I turned up the log level, this pass in extras/plugins/urls.py always caught the ImportError inside my plugin:
# Check if the plugin specifies any base URLs
try:
urlpatterns = import_string(f"{plugin_path}.urls.urlpatterns")
plugin_patterns.append(
path(f"{base_url}/", include((urlpatterns, app.label)))
)
except ImportError:
passI propose replacing the pass with a log message that says something like "could not load plugin base URL {plugin_path}.urls.urlpatterns" and also log a traceback.
Since this mechanism is used to allow having plugins without API URLs (or base URLs), this is not neccessarily an error and should probably be log level INFO and the traceback should be DEBUG, I assume?
I have a patch ready, and can submit a PR, if this seems like a good idea. Log would look something like this:
gunicorn[1337]: Plugin base URL patterns could not be loaded: my_little_plugin.urls.urlpatterns
gunicorn[1337]: Traceback (most recent call last):
gunicorn[1337]: File "/opt/netbox/netbox/extras/plugins/urls.py", line 33, in <module>
gunicorn[1337]: urlpatterns = import_string(f"{plugin_path}.urls.urlpatterns")
gunicorn[1337]: File "/opt/netbox-3.4.0/venv/lib64/python3.8/site-packages/my_little_plugin/forms.py", line 2, in <module>
[...]
gunicorn[1337]: from dcim.models import Devic, Interface
gunicorn[1337]: ImportError: cannot import name 'Devic' from 'dcim.models' (/opt/netbox/netbox/dcim/models/__init__.py)
Use case
I hope this saves plugin developers some head-scratching.
Database changes
No response
External dependencies
No response