From 0a6c630d74da2ed0d7c7ace6520928f2e5a59162 Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Fri, 5 May 2023 20:16:04 +0530 Subject: [PATCH] Revert "Fixes #12463: Fix the association of completed jobs with reports & scripts in the REST API" This reverts commit a29a07ed26b2fe15ea21b000edbede1c20faef93. --- docs/release-notes/version-3.5.md | 1 - netbox/extras/api/views.py | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/docs/release-notes/version-3.5.md b/docs/release-notes/version-3.5.md index 8bdfb1578..4823549fd 100644 --- a/docs/release-notes/version-3.5.md +++ b/docs/release-notes/version-3.5.md @@ -43,7 +43,6 @@ * [#12415](https://github.com/netbox-community/netbox/issues/12415) - Fix `ImportError` exception when running RQ worker * [#12433](https://github.com/netbox-community/netbox/issues/12433) - Correct the application of URL query parameters for object list dashboard widgets * [#12436](https://github.com/netbox-community/netbox/issues/12436) - Remove extraneous "add" button from contact assignments list -* [#12463](https://github.com/netbox-community/netbox/issues/12463) - Fix the association of completed jobs with reports & scripts in the REST API * [#12464](https://github.com/netbox-community/netbox/issues/12464) - Apply credentials for git data source only when connecting via HTTP/S * [#12476](https://github.com/netbox-community/netbox/issues/12476) - Fix `TypeError` exception when running the `runscript` management command * [#12483](https://github.com/netbox-community/netbox/issues/12483) - Fix git remote data syncing when with HTTP proxies defined diff --git a/netbox/extras/api/views.py b/netbox/extras/api/views.py index 3f796d7f8..f302024b0 100644 --- a/netbox/extras/api/views.py +++ b/netbox/extras/api/views.py @@ -187,10 +187,11 @@ class ReportViewSet(ViewSet): """ Compile all reports and their related results (if any). Result data is deferred in the list view. """ + report_content_type = ContentType.objects.get(app_label='extras', model='report') results = { - job.name: job - for job in Job.objects.filter( - object_type=ContentType.objects.get(app_label='extras', model='reportmodule'), + r.name: r + for r in Job.objects.filter( + object_type=report_content_type, status__in=JobStatusChoices.TERMINAL_STATE_CHOICES ).order_by('name', '-created').distinct('name').defer('data') } @@ -201,7 +202,7 @@ class ReportViewSet(ViewSet): # Attach Job objects to each report (if any) for report in report_list: - report.result = results.get(report.name, None) + report.result = results.get(report.full_name, None) serializer = serializers.ReportSerializer(report_list, many=True, context={ 'request': request, @@ -289,10 +290,12 @@ class ScriptViewSet(ViewSet): return module, script def list(self, request): + + script_content_type = ContentType.objects.get(app_label='extras', model='script') results = { - job.name: job - for job in Job.objects.filter( - object_type=ContentType.objects.get(app_label='extras', model='scriptmodule'), + r.name: r + for r in Job.objects.filter( + object_type=script_content_type, status__in=JobStatusChoices.TERMINAL_STATE_CHOICES ).order_by('name', '-created').distinct('name').defer('data') } @@ -303,7 +306,7 @@ class ScriptViewSet(ViewSet): # Attach Job objects to each script (if any) for script in script_list: - script.result = results.get(script.name, None) + script.result = results.get(script.full_name, None) serializer = serializers.ScriptSerializer(script_list, many=True, context={'request': request})