core: raise PropertyMappingExpressionException when PropertyMapping returns Undefined

This commit is contained in:
Jens Langhammer 2020-02-19 16:18:31 +01:00
parent 44cd03654d
commit ac273aab75
1 changed files with 5 additions and 1 deletions

View File

@ -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