Script ignores 'scheduling_enabled' if it has no input parameters #8296

Closed
opened 2025-12-29 20:35:01 +01:00 by adam · 1 comment
Owner

Originally created by @candlerb on GitHub (Jul 5, 2023).

Originally assigned to: @abhi1693 on GitHub.

NetBox version

v3.5.4

Python version

3.8

Steps to Reproduce

Upload the following script and run it:

from extras.scripts import Script

class TestScript(Script):
    class Meta:
        name = "Test Script"
        scheduling_enabled = False

    def run(self, data, commit):
        self.log_success("Run OK")
        return "OK\n"

Expected Behavior

Since scheduling_enabled is False, Netbox should not offer to run the script at scheduled times.

Observed Behavior

image

Note however that commit_default = False is honoured if provided.

Originally created by @candlerb on GitHub (Jul 5, 2023). Originally assigned to: @abhi1693 on GitHub. ### NetBox version v3.5.4 ### Python version 3.8 ### Steps to Reproduce Upload the following script and run it: ``` from extras.scripts import Script class TestScript(Script): class Meta: name = "Test Script" scheduling_enabled = False def run(self, data, commit): self.log_success("Run OK") return "OK\n" ``` ### Expected Behavior Since `scheduling_enabled` is False, Netbox should not offer to run the script at scheduled times. ### Observed Behavior ![image](https://github.com/netbox-community/netbox/assets/44789/c10d6eac-aa7e-4e33-8d98-6077fc757972) Note however that `commit_default = False` *is* honoured if provided.
adam added the type: bugstatus: acceptedseverity: medium labels 2025-12-29 20:35:01 +01:00
adam closed this issue 2025-12-29 20:35:02 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Jul 5, 2023):

Lots of stuff wrong here. To add to the description, it's important to note that if the script has input, the scheduling fields are removed.

The reason they are not getting removed if there is input is because the logic here is wrong:

07ae7c8a6e/netbox/templates/extras/script.html (L18-L38)

The scheduling fields are removed in the get_fieldsets() method, which is only called if form.requires_input is True (L18). If the form doesn't require input the entire form is just rendered.

Now even if that is fixed, the check to prevent scripts from being scheduled is not working either.

The ScriptForm is never passed the scheduling_enabled parameter:

07ae7c8a6e/netbox/extras/scripts.py (L388)

The ScriptForm init method:

07ae7c8a6e/netbox/extras/forms/scripts.py (L37-L47)

Now if the form is fixed and scheduling_enabled is passed to the form, an exception will be thrown here because the previous code pop'ed them already:

07ae7c8a6e/netbox/extras/views.py (L1087)

Open for volunteers.

@kkthxbye-code commented on GitHub (Jul 5, 2023): Lots of stuff wrong here. To add to the description, it's important to note that if the script has input, the scheduling fields are removed. The reason they are not getting removed if there is input is because the logic here is wrong: https://github.com/netbox-community/netbox/blob/07ae7c8a6e04ecc6e641044330fd4d03e4997252/netbox/templates/extras/script.html#L18-L38 The scheduling fields are removed in the get_fieldsets() method, which is only called if `form.requires_input` is True (L18). If the form doesn't require input the entire form is just rendered. Now even if that is fixed, the check to prevent scripts from being scheduled is not working either. The ScriptForm is never passed the `scheduling_enabled` parameter: https://github.com/netbox-community/netbox/blob/07ae7c8a6e04ecc6e641044330fd4d03e4997252/netbox/extras/scripts.py#L388 The ScriptForm init method: https://github.com/netbox-community/netbox/blob/07ae7c8a6e04ecc6e641044330fd4d03e4997252/netbox/extras/forms/scripts.py#L37-L47 Now if the form is fixed and scheduling_enabled is passed to the form, an exception will be thrown here because the previous code pop'ed them already: https://github.com/netbox-community/netbox/blob/07ae7c8a6e04ecc6e641044330fd4d03e4997252/netbox/extras/views.py#L1087 Open for volunteers.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8296