﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31478	Template.get_exception_info() relies on internal state which isn't correct for sub-templates.	Keryn Knight	nobody	"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."	Bug	closed	Template system	dev	Normal	duplicate			Unreviewed	0	0	0	0	0	0
