Possibility to schedule script in the past #11701

Closed
opened 2025-12-29 21:48:47 +01:00 by adam · 3 comments
Owner

Originally created by @rizlas on GitHub (Oct 7, 2025).

Originally assigned to: @pheus on GitHub.

NetBox Edition

NetBox Community

NetBox Version

v4.3.7

Python Version

3.10

Steps to Reproduce

  1. Create a schedule via api with a date in the past
curl -X POST \
-H "Authorization: Token TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json; indent=4" \
https://netbox/api/extras/scripts/your_script/ \
--data '{"data": {}, "schedule_at": "2023-10-07 08:11:00", "interval": 360, "commit": true}'

Expected Behavior

Error from API

Observed Behavior

The script is scheduled, it starts immediately and will keep to schedule new jobs without stopping.

Image
Originally created by @rizlas on GitHub (Oct 7, 2025). Originally assigned to: @pheus on GitHub. ### NetBox Edition NetBox Community ### NetBox Version v4.3.7 ### Python Version 3.10 ### Steps to Reproduce 1. Create a schedule via api with a date in the past ``` curl -X POST \ -H "Authorization: Token TOKEN" \ -H "Content-Type: application/json" \ -H "Accept: application/json; indent=4" \ https://netbox/api/extras/scripts/your_script/ \ --data '{"data": {}, "schedule_at": "2023-10-07 08:11:00", "interval": 360, "commit": true}' ``` ### Expected Behavior Error from API ### Observed Behavior The script is scheduled, it starts immediately and will keep to schedule new jobs without stopping. <img width="1045" height="525" alt="Image" src="https://github.com/user-attachments/assets/de36e72f-1b48-47cb-bf66-d1aea82214b9" />
adam added the type: bugstatus: acceptednetboxseverity: low labels 2025-12-29 21:48:47 +01:00
adam closed this issue 2025-12-29 21:48:48 +01:00
Author
Owner

@jnovinger commented on GitHub (Oct 7, 2025):

Thanks for the bug report, @rizlas . I believe there are actually two bugs here, one of which was fixed in #20243, released in v4.4.2 last week, and ensures that all recurring job runs are at least 1 minute in the future.

The other bug here is that there is inconsistent validation of scheduled times for jobs in UI and the REST API. In the UI, we enforce that all scheduling of jobs must occur in the future, which we do not do in the REST API.

This bug is present and does still need to be fixed.

@jnovinger commented on GitHub (Oct 7, 2025): Thanks for the bug report, @rizlas . I believe there are actually two bugs here, one of which was fixed in #20243, released in v4.4.2 last week, and ensures that all recurring job runs are at least 1 minute in the future. The other bug here is that there is inconsistent validation of scheduled times for jobs in UI and the REST API. In the UI, we enforce that all scheduling of jobs [must occur in the future](https://github.com/netbox-community/netbox/blob/b7cae045725e8316972c58493d8e6f4517c7a95f/netbox/extras/forms/scripts.py#L52-L53), which we [do not do](https://github.com/netbox-community/netbox/blob/b7cae045725e8316972c58493d8e6f4517c7a95f/netbox/extras/api/serializers_/scripts.py#L68-L71) in the REST API. This bug is present and does still need to be fixed.
Author
Owner

@rizlas commented on GitHub (Oct 8, 2025):

Furthermore, if fields with a default setting are not specified in the api data payload, the script will fail. Is this expected and desired behavior?
Example:

debug_mode = BooleanVar("Activate debug mode", default=False)

KeyError: 'debug_mode'
Traceback (most recent call last):
  File "/opt/netbox/netbox/extras/jobs.py", line 46, in run_script
    script.output = script.run(data, commit)
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 145, in run
KeyError: 'debug_mode'

Or

    device_selector = MultiObjectVar(
        description="Limit script to selected devices",
        model=Device,
        query_params={"platform_id": "$platform"},
        required=False,
    )

An exception occurred: KeyError: 'device_selector'

Traceback (most recent call last):
  File "/opt/netbox/netbox/extras/jobs.py", line 46, in run_script
    script.output = script.run(data, commit)
                    ^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 192, in run
KeyError: 'device_selector'

@rizlas commented on GitHub (Oct 8, 2025): Furthermore, if fields with a default setting are not specified in the api data payload, the script will fail. Is this expected and desired behavior? Example: ``` debug_mode = BooleanVar("Activate debug mode", default=False) KeyError: 'debug_mode' Traceback (most recent call last): File "/opt/netbox/netbox/extras/jobs.py", line 46, in run_script script.output = script.run(data, commit) ^^^^^^^^^^^^^^^^^^^^^^^^ File "<string>", line 145, in run KeyError: 'debug_mode' ``` Or ``` device_selector = MultiObjectVar( description="Limit script to selected devices", model=Device, query_params={"platform_id": "$platform"}, required=False, ) An exception occurred: KeyError: 'device_selector' Traceback (most recent call last): File "/opt/netbox/netbox/extras/jobs.py", line 46, in run_script script.output = script.run(data, commit) ^^^^^^^^^^^^^^^^^^^^^^^^ File "<string>", line 192, in run KeyError: 'device_selector' ```
Author
Owner

@pheus commented on GitHub (Oct 17, 2025):

I’d like to work on this. I’ll add API validation to reject past schedule_at values and also handle the “interval‑only” case. Could you assign this to me? Thanks!

@rizlas If there’s a related enhancement or bug, could you open a separate issue for it?

@pheus commented on GitHub (Oct 17, 2025): I’d like to work on this. I’ll add API validation to reject past schedule_at values and also handle the “interval‑only” case. Could you assign this to me? Thanks! @rizlas If there’s a related enhancement or bug, could you open a separate issue for it?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11701