1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #12167: Catch and report on exceptions raised when rendering a config template

This commit is contained in:
jeremystretch
2023-04-04 08:47:01 -04:00
parent 13cbb33c98
commit 1b5f926e17
2 changed files with 9 additions and 1 deletions

View File

@ -80,6 +80,8 @@ Two new webhook trigger events have been introduced: `job_start` and `job_end`.
* [#12144](https://github.com/netbox-community/netbox/issues/12144) - Ensure consistent treatment of context data when rendering config templates via UI & API
* [#12145](https://github.com/netbox-community/netbox/issues/12145) - Employ `HTMXSelect` widget to fix inclusion of `<select>` field values during form regeneration
* [#12146](https://github.com/netbox-community/netbox/issues/12146) - Do not display object selector for disabled fields
* [#12151](https://github.com/netbox-community/netbox/issues/12151) - Remove incorrect OpenAPI string mapping for choice fields
* [#12167](https://github.com/netbox-community/netbox/issues/12167) - Catch and report on exceptions raised when rendering a config template
### Other Changes

View File

@ -1,3 +1,4 @@
from jinja2.exceptions import TemplateError
from rest_framework.response import Response
from .nested_serializers import NestedConfigTemplateSerializer
@ -32,7 +33,12 @@ class ConfigContextQuerySetMixin:
class ConfigTemplateRenderMixin:
def render_configtemplate(self, request, configtemplate, context):
output = configtemplate.render(context=context)
try:
output = configtemplate.render(context=context)
except TemplateError as e:
return Response({
'detail': f"An error occurred while rendering the template (line {e.lineno}): {e}"
}, status=500)
# If the client has requested "text/plain", return the raw content.
if request.accepted_renderer.format == 'txt':