Job scheduling is not working #10472

Closed
opened 2025-12-29 21:31:56 +01:00 by adam · 2 comments
Owner

Originally created by @miaow2 on GitHub (Nov 13, 2024).

Deployment Type

Self-hosted

Triage priority

I volunteer to perform this work (if approved)

NetBox Version

v4.1.6

Python Version

3.11

Steps to Reproduce

  1. Create any script
from extras.scripts import Script


class TestScript(Script):

    def run(self, data, commit):
        self.log_info("This is test script")
  1. Run the script with any interval set
    image

Expected Behavior

The script successfully runs and creates a new scheduled job

Observed Behavior

A new job is not scheduled, traceback from worker

13:48:59 default: handle(commit=True, data={}, job=<Job: 086a5aae-5c60-4746-bde4-f77800c795ea>, request=<utilities.request.NetBoxFakeRequest object at 0x7fba0c3b7ef0>) (086a5aae-5c60-4746-bde4-f77800c795ea)
13:48:59 [Job 086a5aae-5c60-4746-bde4-f77800c795ea]: exception raised while executing (handle)
Traceback (most recent call last):
  File "/home/miaow/work/netbox/venv/lib/python3.12/site-packages/rq/worker.py", line 1430, in perform_job
    rv = job.perform()
         ^^^^^^^^^^^^^
  File "/home/miaow/work/netbox/venv/lib/python3.12/site-packages/rq/job.py", line 1280, in perform
    self._result = self._execute()
                   ^^^^^^^^^^^^^^^
  File "/home/miaow/work/netbox/venv/lib/python3.12/site-packages/rq/job.py", line 1317, in _execute
    result = self.func(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/miaow/work/netbox/netbox/netbox/jobs.py", line 74, in handle
    cls.enqueue(
  File "/home/miaow/work/netbox/netbox/netbox/jobs.py", line 107, in enqueue
    return Job.enqueue(cls.handle, name=name, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/miaow/work/netbox/netbox/core/models/jobs.py", line 237, in enqueue
    job.full_clean()
  File "/home/miaow/work/netbox/venv/lib/python3.12/site-packages/django/db/models/base.py", line 1502, in full_clean
    raise ValidationError(errors)
django.core.exceptions.ValidationError: {'name': ['This field cannot be blank.']}

This happens because the rescheduling mechanism does not pass name to the Job enqueue and name field is obligatory in Job model.

This can be fixed by passing job.name to cls.enqueue here.

Feel free to assign this issue to me, I will create PR to fix this issue.A new

Originally created by @miaow2 on GitHub (Nov 13, 2024). ### Deployment Type Self-hosted ### Triage priority I volunteer to perform this work (if approved) ### NetBox Version v4.1.6 ### Python Version 3.11 ### Steps to Reproduce 1. Create any script ```python from extras.scripts import Script class TestScript(Script): def run(self, data, commit): self.log_info("This is test script") ``` 2. Run the script with any interval set ![image](https://github.com/user-attachments/assets/40418035-f6c9-403d-9057-4ac74cbd7641) ### Expected Behavior The script successfully runs and creates a new scheduled job ### Observed Behavior A new job is not scheduled, traceback from worker ``` 13:48:59 default: handle(commit=True, data={}, job=<Job: 086a5aae-5c60-4746-bde4-f77800c795ea>, request=<utilities.request.NetBoxFakeRequest object at 0x7fba0c3b7ef0>) (086a5aae-5c60-4746-bde4-f77800c795ea) 13:48:59 [Job 086a5aae-5c60-4746-bde4-f77800c795ea]: exception raised while executing (handle) Traceback (most recent call last): File "/home/miaow/work/netbox/venv/lib/python3.12/site-packages/rq/worker.py", line 1430, in perform_job rv = job.perform() ^^^^^^^^^^^^^ File "/home/miaow/work/netbox/venv/lib/python3.12/site-packages/rq/job.py", line 1280, in perform self._result = self._execute() ^^^^^^^^^^^^^^^ File "/home/miaow/work/netbox/venv/lib/python3.12/site-packages/rq/job.py", line 1317, in _execute result = self.func(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/miaow/work/netbox/netbox/netbox/jobs.py", line 74, in handle cls.enqueue( File "/home/miaow/work/netbox/netbox/netbox/jobs.py", line 107, in enqueue return Job.enqueue(cls.handle, name=name, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/miaow/work/netbox/netbox/core/models/jobs.py", line 237, in enqueue job.full_clean() File "/home/miaow/work/netbox/venv/lib/python3.12/site-packages/django/db/models/base.py", line 1502, in full_clean raise ValidationError(errors) django.core.exceptions.ValidationError: {'name': ['This field cannot be blank.']} ``` This happens because the rescheduling mechanism does not pass `name` to the Job enqueue and `name` field is obligatory in Job model. This can be fixed by passing `job.name` to `cls.enqueue` [here](https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/jobs.py#L73). Feel free to assign this issue to me, I will create PR to fix this issue.A new
adam added the type: bugstatus: duplicatenetbox labels 2025-12-29 21:31:56 +01:00
adam closed this issue 2025-12-29 21:31:56 +01:00
Author
Owner

@alehaa commented on GitHub (Nov 13, 2024):

This issue is a duplicate of https://github.com/netbox-community/netbox/issues/17923, https://github.com/netbox-community/netbox/issues/17921. A PR is already provided and ready to merge. :)

@alehaa commented on GitHub (Nov 13, 2024): This issue is a duplicate of https://github.com/netbox-community/netbox/issues/17923, https://github.com/netbox-community/netbox/issues/17921. A PR is already provided and ready to merge. :)
Author
Owner

@jeremystretch commented on GitHub (Nov 21, 2024):

This appears to be a duplicate of #17921, which has been resolved by PR #17932.

@jeremystretch commented on GitHub (Nov 21, 2024): This appears to be a duplicate of #17921, which has been resolved by PR #17932.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10472