Exception for job list if object not set #10326

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

Originally created by @alehaa on GitHub (Oct 7, 2024).

Deployment Type

Self-hosted

NetBox Version

v4.1.3

Python Version

3.11

Steps to Reproduce

  1. Create a new JobRunner.
  2. Schedule the job runner without an instance being passed to enqueue_once().
  3. Navigate to jobs list view

Expected Behavior

List is shown

Observed Behavior

AttributeError at /core/jobs/

'NoneType' object has no attribute 'model'

This seems to be similar to #17086, but I don't know why it wasn't observed in previous versions.

As this blocks implementation of #16971 or at least makes the changes impractical to use, I'd like to check on this issue first (and volunteer for a PR).

Originally created by @alehaa on GitHub (Oct 7, 2024). ### Deployment Type Self-hosted ### NetBox Version v4.1.3 ### Python Version 3.11 ### Steps to Reproduce 1. Create a new JobRunner. 2. Schedule the job runner without an instance being passed to `enqueue_once()`. 3. Navigate to jobs list view ### Expected Behavior List is shown ### Observed Behavior > AttributeError at /core/jobs/ > > 'NoneType' object has no attribute 'model' This seems to be similar to #17086, but I don't know why it wasn't observed in previous versions. As this blocks implementation of #16971 or at least makes the changes impractical to use, I'd like to check on this issue first (and volunteer for a PR).
adam added the type: bug label 2025-12-29 21:30:00 +01:00
adam closed this issue 2025-12-29 21:30:00 +01:00
Author
Owner

@alehaa commented on GitHub (Oct 7, 2024):

In core.Job, object_type is optional. However, its get_absolute_url() method assumes it not to be None. Required changes:

diff --git a/netbox/core/models/jobs.py b/netbox/core/models/jobs.py
index 4a327a1d8..499822468 100644
--- a/netbox/core/models/jobs.py
+++ b/netbox/core/models/jobs.py
@@ -118,9 +118,9 @@ class Job(models.Model):
 
     def get_absolute_url(self):
         # TODO: Employ dynamic registration
-        if self.object_type.model == 'reportmodule':
+        if self.object_type and self.object_type.model == 'reportmodule':
             return reverse(f'extras:report_result', kwargs={'job_pk': self.pk})
-        if self.object_type.model == 'scriptmodule':
+        if self.object_type and self.object_type.model == 'scriptmodule':
             return reverse(f'extras:script_result', kwargs={'job_pk': self.pk})
         return reverse('core:job', args=[self.pk])
@alehaa commented on GitHub (Oct 7, 2024): In `core.Job`, `object_type` is optional. However, its `get_absolute_url()` method assumes it not to be `None`. Required changes: ```diff diff --git a/netbox/core/models/jobs.py b/netbox/core/models/jobs.py index 4a327a1d8..499822468 100644 --- a/netbox/core/models/jobs.py +++ b/netbox/core/models/jobs.py @@ -118,9 +118,9 @@ class Job(models.Model): def get_absolute_url(self): # TODO: Employ dynamic registration - if self.object_type.model == 'reportmodule': + if self.object_type and self.object_type.model == 'reportmodule': return reverse(f'extras:report_result', kwargs={'job_pk': self.pk}) - if self.object_type.model == 'scriptmodule': + if self.object_type and self.object_type.model == 'scriptmodule': return reverse(f'extras:script_result', kwargs={'job_pk': self.pk}) return reverse('core:job', args=[self.pk]) ```
Author
Owner

@alehaa commented on GitHub (Oct 7, 2024):

I believe this is a duplicate of #17566. Sorry.

@alehaa commented on GitHub (Oct 7, 2024): I believe this is a duplicate of #17566. Sorry.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10326