From 12d735ec8f22057a7b82c69e744ca3ee1bca0d38 Mon Sep 17 00:00:00 2001 From: Jim Ladd Date: Thu, 17 Oct 2019 23:51:55 -0700 Subject: [PATCH] NotificationSerializer should gracefully handle webhook/pagerduty bodies --- awx/api/serializers.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 3931654a95..eaa5ec7e4c 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -4514,8 +4514,18 @@ class NotificationSerializer(BaseSerializer): 'notification_type', 'recipients', 'subject', 'body') def get_body(self, obj): - if obj.notification_type == 'webhook' and 'body' in obj.body: - return obj.body['body'] + if obj.notification_type in ('webhook', 'pagerduty'): + if isinstance(obj.body, dict): + if 'body' in obj.body: + return obj.body['body'] + elif isinstance(obj.body, str): + # attempt to load json string + try: + potential_body = json.loads(obj.body) + if isinstance(potential_body, dict) and 'body' in potential_body: + return potential_body['body'] + except json.JSONDecodeError: + pass return obj.body def get_related(self, obj):