From 56b6a07f6ee24ee52b2e21b3b48576e1b1e8bb28 Mon Sep 17 00:00:00 2001 From: Dave Date: Mon, 12 Feb 2024 15:43:43 +0000 Subject: [PATCH] Remove json serialization for notify validation (#14847) * Remove json serialization for notify validation * Update serializers.py --- awx/api/serializers.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index e17fe41fd708..3868ae1eec98 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -5177,16 +5177,21 @@ def __init__(self, *args, **kwargs): body = messages[event].get('body', {}) if body: try: - rendered_body = ( - sandbox.ImmutableSandboxedEnvironment(undefined=DescriptiveUndefined).from_string(body).render(JobNotificationMixin.context_stub()) - ) - potential_body = json.loads(rendered_body) - if not isinstance(potential_body, dict): - error_list.append( - _("Webhook body for '{}' should be a json dictionary. Found type '{}'.".format(event, type(potential_body).__name__)) - ) - except json.JSONDecodeError as exc: - error_list.append(_("Webhook body for '{}' is not a valid json dictionary ({}).".format(event, exc))) + sandbox.ImmutableSandboxedEnvironment(undefined=DescriptiveUndefined).from_string(body).render(JobNotificationMixin.context_stub()) + + # https://github.com/ansible/awx/issues/14410 + + # When rendering something such as "{{ job.id }}" + # the return type is not a dict, unlike "{{ job_metadata }}" which is a dict + + # potential_body = json.loads(rendered_body) + + # if not isinstance(potential_body, dict): + # error_list.append( + # _("Webhook body for '{}' should be a json dictionary. Found type '{}'.".format(event, type(potential_body).__name__)) + # ) + except Exception as exc: + error_list.append(_("Webhook body for '{}' is not valid. The following gave an error ({}).".format(event, exc))) if error_list: raise serializers.ValidationError(error_list)