Unable to use plugin models in custom scripts #8015

Closed
opened 2025-12-29 20:31:10 +01:00 by adam · 4 comments
Owner

Originally created by @Bapths on GitHub (May 8, 2023).

NetBox version

v3.4.3

Python version

3.10

Steps to Reproduce

  1. Add a custom script using an installed plugin:
    from myplugin.models import MyPluginModel
    from extras.scripts import *
    
    class MyCustomScript(Script):
        class Meta:
            name = 'My Custom Script'
            description = 'My Custom Script Description'
    
        def run(self, data, commit):
            return 'Test script'
    
  2. Save the file and run the script from the Netbox Web UI.

Expected Behavior

The script should run and output Test script.

Observed Behavior

The script is stuck in pending state.
When we look for the job in the admin panel we can see that the status is failed with the following Exception:

[...]
RuntimeError: Model class myplugin.models.MyPluginModel doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
Originally created by @Bapths on GitHub (May 8, 2023). ### NetBox version v3.4.3 ### Python version 3.10 ### Steps to Reproduce 1. Add a custom script using an installed plugin: ```py from myplugin.models import MyPluginModel from extras.scripts import * class MyCustomScript(Script): class Meta: name = 'My Custom Script' description = 'My Custom Script Description' def run(self, data, commit): return 'Test script' ``` 2. Save the file and run the script from the Netbox Web UI. ### Expected Behavior The script should run and output `Test script`. ### Observed Behavior The script is stuck in pending state. When we look for the job in the admin panel we can see that the status is `failed` with the following Exception: ``` [...] RuntimeError: Model class myplugin.models.MyPluginModel doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS. ```
adam added the type: bugstatus: under review labels 2025-12-29 20:31:10 +01:00
adam closed this issue 2025-12-29 20:31:10 +01:00
Author
Owner

@jsenecal commented on GitHub (May 8, 2023):

How are you running netbox ?

@jsenecal commented on GitHub (May 8, 2023): How are you running netbox ?
Author
Owner

@Bapths commented on GitHub (May 8, 2023):

How are you running netbox ?

I am running Netbox as a service on a virtual machine (Ubuntu Server 22.04.1). I followed the installation guide for the installation. I tried this on different versions of Netbox with the same result. Maybe that is not the way to import my plugin model? Or my plugin may be incomplete or something?

Just adding the import line without even using the model in the script will return the same error.

@Bapths commented on GitHub (May 8, 2023): > How are you running netbox ? I am running Netbox as a service on a virtual machine (Ubuntu Server 22.04.1). I followed the [installation guide](https://docs.netbox.dev/en/stable/installation/) for the installation. I tried this on different versions of Netbox with the same result. Maybe that is not the way to import my plugin model? Or my plugin may be incomplete or something? Just adding the import line without even using the model in the script will return the same error.
Author
Owner

@jsenecal commented on GitHub (May 9, 2023):

Is your worker process running off the same python (virtual?) environment? It seems to me that your plugin is not "installed" for the worker.

@jsenecal commented on GitHub (May 9, 2023): Is your worker process running off the same python (virtual?) environment? It seems to me that your plugin is not "installed" for the worker.
Author
Owner

@Bapths commented on GitHub (May 10, 2023):

Hi @jsenecal,

Given your answer I gave a look to my installation's rq-worker. It appeared that I forgot to restart the netbox-rq service after installing my plugin. A simple sudo systemctl restart netbox-rq solved this issue (maybe adding this to the plugin installation guide would help other users).

Thanks for the help! 😉

@Bapths commented on GitHub (May 10, 2023): Hi @jsenecal, Given your answer I gave a look to my installation's rq-worker. It appeared that I forgot to restart the netbox-rq service after installing my plugin. A simple `sudo systemctl restart netbox-rq` solved this issue (maybe adding this to the plugin installation guide would help other users). Thanks for the help! 😉
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8015