#31478: Template.get_exception_info relies on internal state which isn't correct
for sub-templates.
-------------------------------------------+------------------------
               Reporter:  Keryn Knight     |          Owner:  nobody
                   Type:  Bug              |         Status:  new
              Component:  Template system  |        Version:  master
               Severity:  Normal           |       Keywords:
           Triage Stage:  Unreviewed       |      Has patch:  0
    Needs documentation:  0                |    Needs tests:  0
Patch needs improvement:  0                |  Easy pickings:  0
                  UI/UX:  0                |
-------------------------------------------+------------------------
 Currently, the method is defined as:
 {{{
 def get_exception_info(self, exception, token):
 }}}
 and internal to it's scope, makes use of the values `self.source` and
 `self.origin.name`

 These 2 variables are not necessarily the data on which the operations
 should apply, at least in some scenarios. I have a demo project while I'll
 attach to hopefully demonstrate this.

 The problem exists on 2.2, 3.0 & master (being 3.1 currently). Whilst I've
 not done an exhaustive sweep of the potential problems, a solution which
 seems to work in my limited test is thus:

 Method signature becomes
 {{{
 def get_exception_info(self, exception, token, origin=None, source=None):
         if source is None:
             source = self.source
         if origin is None:
             origin = self.origin
 }}}
 Why support Nones? Because at the very least I think django-debug-toolbar
 makes use of the method, and it leaves it backwards compatible.

 The callers I'm aware of are
 `django.template.base.Template.compile_nodelist`, which would become:
 {{{
 e.template_debug = self.get_exception_info(e, e.token, self.origin,
 self.source)
 }}}
 though I think that given that is passing in the *same* data, it could
 actually remain unchanged, because the internal state is the same both
 ways.

 ... and `django.template.base.Node.render_annotated`:
 {{{
 e.template_debug = context.render_context.template.get_exception_info(e,
 self.token, context.template.origin, context.template.source)
 }}}
 This one is what I presume is the crux of the problem, because the render
 context's template is not the same as the child template.

 Of course, changing the origin and source might have other knock on
 effects that I've not encountered in my tests, and I haven't tried the
 proposed changes against the test suite etc.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31478>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.e926d32f7e8d8c0286670f3e56dcb08b%40djangoproject.com.

Reply via email to