From 6aca9d80bb6221b2a253271e3b46c84044ba747e Mon Sep 17 00:00:00 2001 From: Saurabh Thakre Date: Thu, 18 Feb 2021 12:24:14 +0000 Subject: [PATCH] Updated notifications.py Fixed the customized notification returning incorrect values for host_status_counts Update notifications.py Removed if condition Added exception handling A nitpick --- awx/main/models/notifications.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/awx/main/models/notifications.py b/awx/main/models/notifications.py index 74a9896385..c1fc123173 100644 --- a/awx/main/models/notifications.py +++ b/awx/main/models/notifications.py @@ -383,12 +383,17 @@ class JobNotificationMixin(object): and a url to the job run.""" job_context = {'host_status_counts': {}} summary = None - if hasattr(self, 'job_host_summaries'): - summary = self.job_host_summaries.first() - if summary: - from awx.api.serializers import JobHostSummarySerializer - summary_data = JobHostSummarySerializer(summary).to_representation(summary) - job_context['host_status_counts'] = summary_data + try: + has_event_property = any([f for f in self.event_class._meta.fields if f.name == 'event']) + except NotImplementedError: + has_event_property = False + if has_event_property: + qs = self.get_event_queryset() + if qs: + event = qs.only('event_data').filter(event='playbook_on_stats').first() + if event: + summary = event.get_host_status_counts() + job_context['host_status_counts'] = summary context = { 'job': job_context, 'job_friendly_name': self.get_notification_friendly_name(),