Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in execution of scheduled jobs created by REST API #1787

Closed
glennmatthews opened this issue May 18, 2022 · 1 comment · Fixed by #1840
Closed

Error in execution of scheduled jobs created by REST API #1787

glennmatthews opened this issue May 18, 2022 · 1 comment · Fixed by #1840
Assignees
Labels
type: bug Something isn't working as expected

Comments

@glennmatthews
Copy link
Contributor

Environment

  • Python version:
  • Nautobot version: 1.3.3

Steps to Reproduce

  1. Use the REST API to create a ScheduledJob entry (this issue is not seen with ScheduledJobs created via the UI)
  2. Observe worker logs at the time when the ScheduledJob is supposed to execute

Expected Behavior

Successful execution of the job

Observed Behavior

2022-05-18 08:47:08,148: ERROR/ForkPoolWorker-6] Task nautobot.extras.jobs.scheduled_job_handler[9c03a139-3dba-4a10-bc1b-fd1881600613] raised unexpected: KeyError('scheduled_job_pk')
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/celery/app/trace.py", line 451, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/celery/app/trace.py", line 734, in __protected_call__
    return self.run(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/nautobot/extras/jobs.py", line 1203, in scheduled_job_handler
    scheduled_job_pk = kwargs.pop("scheduled_job_pk")
KeyError: 'scheduled_job_pk'

Analysis

nautobot/extras/views.py has the following:

                scheduled_job = ScheduledJob(
                    name=schedule_name,
                    task="nautobot.extras.jobs.scheduled_job_handler",
                    job_class=job_model.class_path,
                    job_model=job_model,
                    start_time=schedule_datetime,
                    description=f"Nautobot job {schedule_name} scheduled by {request.user} for {schedule_datetime}",
                    kwargs=job_kwargs,
                    interval=schedule_type,
                    one_off=schedule_type == JobExecutionType.TYPE_FUTURE,
                    user=request.user,
                    approval_required=job_model.approval_required,
                )   
                scheduled_job.kwargs["scheduled_job_pk"] = scheduled_job.pk
                scheduled_job.save()

while nautobot/extras/api/views.py has the following:

    scheduled_job = ScheduledJob(
        name=name,
        task="nautobot.extras.jobs.scheduled_job_handler",
        job_class=job.class_path,
        job_model=job_model,
        start_time=time,
        description=f"Nautobot job {name} scheduled by {request.user} on {time}",
        kwargs=job_kwargs,
        interval=type_,
        one_off=(type_ == JobExecutionType.TYPE_FUTURE),
        user=request.user,
        approval_required=job_model.approval_required,
    )
    scheduled_job.save()

It appears that the API view is failing to set the scheduled_job_pk on the kwargs when compared to the UI view.

@glennmatthews glennmatthews added the type: bug Something isn't working as expected label May 18, 2022
@lvrfrc87
Copy link
Contributor

Thanks @glennmatthews to raise this issue.
Any idea in which release would be fixed?

@gsnider2195 gsnider2195 self-assigned this Jun 1, 2022
gsnider2195 added a commit that referenced this issue Jun 3, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
No open projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants