You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing a custom reservation plugin so that when an object is created, the save() function creates a background job which changes the object's status from Active to Inactive at the reservation's end date. I've written my jobs based on this doc, and it creates the job, but when the job executes at the scheduled time, it errors out with AttributeError("'NoneType' object has no attribute 'status'"). I'm also unable to get a stack trace of this error from logs, and unable to find the setting that I need to change this.
Using nbshell to test this further, I found the job executes accurately when ran with MyJob.enqueue(immediate=True), but produces the error above when executed with MyJob.enqueue(schedule_at=datetime). This is with Netbox v4.2.7, running in Docker container v3.2.0.
The part of my code to enqueue the script is in this block in models.py:
@receiver(post_save, sender=Reservation)
def create_job(sender, instance, created, **kwargs):
# don't make any jobs if status is already inactive
if instance.status != StatusChoices.STATUS_INACTIVE:
ActiveToInactiveJob.enqueue_once(instance=instance, schedule_at=instance.end_date, status_choices=StatusChoices)
The job being executed from jobs.py:
class ActiveToInactiveJob(JobRunner):
class Meta:
name = "Status Updater: Active to Inactive"
def run(self, status_choices, *args, **kwargs):
obj = self.job.object
if obj.status == status_choices.STATUS_ACTIVE:
obj.status = status_choices.STATUS_INACTIVE
obj.save()
else:
raise ValidationError(("Status provided is not valid for scheduled Active to Inactive update! Received: %(status)s"), params={"status": obj.status})
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm writing a custom reservation plugin so that when an object is created, the
save()
function creates a background job which changes the object's status from Active to Inactive at the reservation's end date. I've written my jobs based on this doc, and it creates the job, but when the job executes at the scheduled time, it errors out withAttributeError("'NoneType' object has no attribute 'status'")
. I'm also unable to get a stack trace of this error from logs, and unable to find the setting that I need to change this.Using nbshell to test this further, I found the job executes accurately when ran with
MyJob.enqueue(immediate=True)
, but produces the error above when executed withMyJob.enqueue(schedule_at=datetime)
. This is with Netbox v4.2.7, running in Docker container v3.2.0.The part of my code to enqueue the script is in this block in
models.py
:The job being executed from
jobs.py
:Beta Was this translation helpful? Give feedback.
All reactions