core: raise PropertyMappingExpressionException when PropertyMapping returns Undefined
This commit is contained in:
parent
44cd03654d
commit
ac273aab75
|
@ -15,6 +15,7 @@ from django.utils.timezone import now
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django_prometheus.models import ExportModelOperationsMixin
|
from django_prometheus.models import ExportModelOperationsMixin
|
||||||
from guardian.mixins import GuardianUserMixin
|
from guardian.mixins import GuardianUserMixin
|
||||||
|
from jinja2 import Undefined
|
||||||
from jinja2.exceptions import TemplateSyntaxError, UndefinedError
|
from jinja2.exceptions import TemplateSyntaxError, UndefinedError
|
||||||
from jinja2.nativetypes import NativeEnvironment
|
from jinja2.nativetypes import NativeEnvironment
|
||||||
from model_utils.managers import InheritanceManager
|
from model_utils.managers import InheritanceManager
|
||||||
|
@ -313,7 +314,10 @@ class PropertyMapping(UUIDModel):
|
||||||
except TemplateSyntaxError as exc:
|
except TemplateSyntaxError as exc:
|
||||||
raise PropertyMappingExpressionException from exc
|
raise PropertyMappingExpressionException from exc
|
||||||
try:
|
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:
|
except UndefinedError as exc:
|
||||||
raise PropertyMappingExpressionException from exc
|
raise PropertyMappingExpressionException from exc
|
||||||
|
|
||||||
|
|
Reference in a new issue