-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
NetBox version
V3.0.9
Feature type
Change to existing functionality
Proposed functionality
Allow renaming of classes in custom scripts. Currently if you rename a class or remove a class from a file, netbox will throw OSError : could not find class definition and the script functionality will be broken until the application server is restarted.
The reason for this is that python uses sys.modules to cache all imported modules. When you change a class in the script and reload it in get_scripts, which is called on both the list view and when executing scripts, the module includes both the old name for the class and the new name (not sure why), causing the import to fail on the old name.
The solution is pretty simple, deleting the module from sys.modules. A simple implementation can be seen here:
I wasn't able to notice any performance regressions, the extra load should be minimal even with a lot of scripts. The advantage is that the loaded script is actually correct.
Use case
Scripts already allow changing code without restart, with the requested change you will also be able to rename or delete script classes.
Database changes
None
External dependencies
None