Script overview page does not show the last run/status of script job exection in 4.1.x #10250

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

Originally created by @timeu on GitHub (Sep 16, 2024).

Originally assigned to: @arthanson on GitHub.

Deployment Type

Self-hosted

NetBox Version

v4.1.1

Python Version

3.10

Steps to Reproduce

  1. Add a dummy script:
from django.db.models import Count, Q

from dcim.models import Cable
from extras.scripts import Script


class Test(Script):
    class Meta:
        name = f'test'
        description = f'test'

    def test_report(self):
        pass

  1. Execute the script
  2. Navigate to the script overview

Expected Behavior

Last Run and Status should be displayed corectly (job run date and status)

Observed Behavior

"Last Run" column shows "Never" and status is empty.

image

image

I believe the issue is:

The name of the script job is set to empty string here but the view template (https://github.com/netbox-community/netbox/blob/develop/netbox/templates/extras/script_list.html#L53) filters the last job on the scipt name.

Originally created by @timeu on GitHub (Sep 16, 2024). Originally assigned to: @arthanson on GitHub. ### Deployment Type Self-hosted ### NetBox Version v4.1.1 ### Python Version 3.10 ### Steps to Reproduce 1. Add a dummy script: ``` from django.db.models import Count, Q from dcim.models import Cable from extras.scripts import Script class Test(Script): class Meta: name = f'test' description = f'test' def test_report(self): pass ``` 2. Execute the script 3. Navigate to the script overview ### Expected Behavior Last Run and Status should be displayed corectly (job run date and status) ### Observed Behavior "Last Run" column shows "Never" and status is empty. ![image](https://github.com/user-attachments/assets/25e5ebc7-7eee-4060-ae03-d5b0582c7d59) ![image](https://github.com/user-attachments/assets/0abf8c4a-b76a-400b-9eb1-c96fb5578b11) I believe the issue is: The name of the script job is set to empty string [here](https://github.com/netbox-community/netbox/blob/develop/netbox/extras/jobs.py#L27) but the view template (https://github.com/netbox-community/netbox/blob/develop/netbox/templates/extras/script_list.html#L53) filters the last job on the scipt name.
adam added the type: bugstatus: acceptedseverity: low labels 2025-12-29 21:28:52 +01:00
adam closed this issue 2025-12-29 21:28:52 +01:00
Author
Owner

@alehaa commented on GitHub (Sep 16, 2024):

That a Script job doesn't have a name is correct, as its identified by the script instance linked to it.

To fix this issue, I believe JobsMixin.get_latest_jobs() must not use the name as key for the dictionary being generated and also not sort by name. Afterwards it should be sufficient to just get the latest job of the script using last_job=script.get_latest_jobs|first, if needed filtering name='' to allow future extensions.

@alehaa commented on GitHub (Sep 16, 2024): That a `Script` job doesn't have a name is correct, as its identified by the script instance linked to it. To fix this issue, I believe [`JobsMixin.get_latest_jobs()`](https://github.com/netbox-community/netbox/blob/0e34fba92223348e0bf4375b8d380324ff5e1beb/netbox/netbox/models/features.py#L409) must not use the `name` as key for the dictionary being generated and also not sort by name. Afterwards it should be sufficient to just get the latest job of the script using `last_job=script.get_latest_jobs|first`, if needed filtering `name=''` to allow future extensions.
Author
Owner

@timeu commented on GitHub (Sep 16, 2024):

@alehaa : Sounds right. This will work also with script instances that contain multiple classes which have their own job runs ?

@timeu commented on GitHub (Sep 16, 2024): @alehaa : Sounds right. This will work also with script instances that contain multiple classes which have their own job runs ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10250