Switch Jinja2 environment for rendering before testing JSON to ImmutableSandboxedEnvironment

Render Jinja template before checking for valid JSON
This commit is contained in:
John Maynard 2021-12-01 15:22:27 -05:00 committed by Lila
parent 8c3e289170
commit 8a5e89e24b

View File

@ -4480,7 +4480,10 @@ class NotificationTemplateSerializer(BaseSerializer):
body = messages[event].get('body', {})
if body:
try:
potential_body = json.loads(body)
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__))