#30425: Handle `jinja2.TemplateSyntaxError` when rendering a template with or
without a source.
---------------------------------+------------------------------------
     Reporter:  Daniel Hahler    |                    Owner:  nobody
         Type:  Bug              |                   Status:  new
    Component:  Template system  |                  Version:  master
     Severity:  Normal           |               Resolution:
     Keywords:                   |             Triage Stage:  Accepted
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  0
---------------------------------+------------------------------------
Changes (by felixxm):

 * version:  2.2 => master
 * stage:  Unreviewed => Accepted


Comment:

 We don't catch `jinja2.TemplateSyntaxError` in
 
[https://github.com/django/django/blob/673fe2e3ec63614259e86e7a370b9d1e91fcc1e1/django/template/backends/jinja2.py#L61-L71
 `Template.render()`], hence `get_exception_info()` is not called when
 `jinja2.TemplateSyntaxError` is raised in rendering i.e. when `source` can
 be `None`.

 I agree that we should catch  `jinja2.TemplateSyntaxError` in
 `Template.render()` and in such case fix issue with `source = None`:

 {{{ #!python
 def render(self, context=None, request=None):
     try:
         ...
         return self.template.render(context)
     except jinja2.TemplateSyntaxError as exc:
         new = TemplateSyntaxError(exc.args)
         new.template_debug = get_exception_info(exc)
         raise new from exc
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30425#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.8a07a6b8c1d18ac4e2312daeebd2b5f4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to