From ac273aab759498c7d792eceb6b7e9c638e0906e3 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Wed, 19 Feb 2020 16:18:31 +0100 Subject: [PATCH] core: raise PropertyMappingExpressionException when PropertyMapping returns Undefined --- passbook/core/models.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/passbook/core/models.py b/passbook/core/models.py index 530c08b60..bcd00b43b 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -15,6 +15,7 @@ from django.utils.timezone import now from django.utils.translation import gettext_lazy as _ from django_prometheus.models import ExportModelOperationsMixin from guardian.mixins import GuardianUserMixin +from jinja2 import Undefined from jinja2.exceptions import TemplateSyntaxError, UndefinedError from jinja2.nativetypes import NativeEnvironment from model_utils.managers import InheritanceManager @@ -313,7 +314,10 @@ class PropertyMapping(UUIDModel): except TemplateSyntaxError as exc: raise PropertyMappingExpressionException from exc try: - return expression.render(user=user, request=request, **kwargs) + response = expression.render(user=user, request=request, **kwargs) + if isinstance(response, Undefined): + raise PropertyMappingExpressionException("Response was 'Undefined'") + return response except UndefinedError as exc: raise PropertyMappingExpressionException from exc