Remove json serialization for notify validation (#14847)

* Remove json serialization for notify validation

* Update serializers.py
This commit is contained in:
Dave
2024-02-12 15:43:43 +00:00
committed by GitHub
parent 519fd22bec
commit 56b6a07f6e

View File

@@ -5177,16 +5177,21 @@ class NotificationTemplateSerializer(BaseSerializer):
body = messages[event].get('body', {}) body = messages[event].get('body', {})
if body: if body:
try: try:
rendered_body = (
sandbox.ImmutableSandboxedEnvironment(undefined=DescriptiveUndefined).from_string(body).render(JobNotificationMixin.context_stub()) sandbox.ImmutableSandboxedEnvironment(undefined=DescriptiveUndefined).from_string(body).render(JobNotificationMixin.context_stub())
)
potential_body = json.loads(rendered_body) # https://github.com/ansible/awx/issues/14410
if not isinstance(potential_body, dict):
error_list.append( # When rendering something such as "{{ job.id }}"
_("Webhook body for '{}' should be a json dictionary. Found type '{}'.".format(event, type(potential_body).__name__)) # the return type is not a dict, unlike "{{ job_metadata }}" which is a dict
)
except json.JSONDecodeError as exc: # potential_body = json.loads(rendered_body)
error_list.append(_("Webhook body for '{}' is not a valid json dictionary ({}).".format(event, exc)))
# 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: if error_list:
raise serializers.ValidationError(error_list) raise serializers.ValidationError(error_list)