Repository: netbox-community/netbox
Pull request: Closes: #14570 - Remove extra query for job under scripts and reports detailed view
### Closes: #14570

* Remove extra query for job under scripts and reports detailed view
  * This query supports populating the .results property on the script model, however this property is no longer used as the results have been moved to their own view.

Problem statement:
Remove results query from extras/views.py under ScriptView.get()
### Proposed Changes

Remove:

```
        # Look for a pending Job (use the latest one by creation timestamp)
        object_type = ContentType.objects.get(app_label='extras', model='scriptmodule')
        script.result = Job.objects.filter(
            object_type=object_type,
            object_id=module.pk,
            name=script.class_name,
        ).exclude(
            status__in=JobStatusChoices.TERMINAL_STATE_CHOICES
        ).first()
```

### Justification

This appears to be extraneous code that was left over from when results were handled inline.  This is no longer needed as the result is a separate view.

`result` is not referenced anywhere in the template.

Hints from issue discussion:

Commit message: Closes: #14570 - Remove extra query for job under scripts and reports detailed view

Patch to review:
diff --git a/netbox/extras/views.py b/netbox/extras/views.py
index 56a497f8d71..6e9508f879a 100644
--- a/netbox/extras/views.py
+++ b/netbox/extras/views.py
@@ -1059,10 +1059,6 @@ def get(self, request, module, name):
         report = module.reports[name]()
         jobs = module.get_jobs(report.class_name)
 
-        report.result = jobs.filter(
-            status__in=JobStatusChoices.TERMINAL_STATE_CHOICES
-        ).first()
-
         return render(request, 'extras/report.html', {
             'job_count': jobs.count(),
             'module': module,
@@ -1233,11 +1229,6 @@ def get(self, request, module, name):
         jobs = module.get_jobs(script.class_name)
         form = script.as_form(initial=normalize_querydict(request.GET))
 
-        # Look for a pending Job (use the latest one by creation timestamp)
-        script.result = module.get_jobs(script.class_name).exclude(
-            status__in=JobStatusChoices.TERMINAL_STATE_CHOICES
-        ).first()
-
         return render(request, 'extras/script.html', {
             'job_count': jobs.count(),
             'module': module,


Code review comments:
diff_hunk: @@ -1059,10 +1059,6 @@ def get(self, request, module, name):
         report = module.reports[name]()
         jobs = module.get_jobs(report.class_name)
 
-        report.result = jobs.filter(
path: netbox/extras/views.py
text: @user1:
`report.result` is referenced by the `report.html` template to display the time at which the report was most recently run.

@author:
Sorry, I must have missed that one, putting it back in.