As a fix I'd like the ability to log these exceptions via the normal
logging facilities, something akin to
[https://github.com/django/django/commit/dc5b01ad05e50ccde688c73c2ed3334a956076b0
#diff-43474443052641e2941ca9fd04138c6bR124 this change]:
The problematic exception catching line is
[https://github.com/django/django/blob/master/django/template/loader_tags.py#L207
here]
[https://github.com/limnick/djangoadminexception_testcase example with
reproduction steps]
--
Ticket URL: <https://code.djangoproject.com/ticket/25373>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* component: contrib.admin => Template system
* needs_tests: => 0
* easy: 1 => 0
* needs_docs: => 0
* type: Bug => New feature
* stage: Unreviewed => Accepted
Comment:
Updated title to reflect that the issue is really about the template
system and the `{% include %}` template tag, not the admin. As the docs
note:
When debug mode is turned on, an exception like `TemplateDoesNotExist` or
`TemplateSyntaxError` will be raised; otherwise `{% include %}` silences
any exception that happens while rendering the included template and
returns an empty string.
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:1>
Comment (by limnick):
if you want these logged via the django.template logger I can put a patch
together with a fix and a regression test for review
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:2>
Comment (by timgraham):
I didn't have an alternate implementation in mind.
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:3>
* owner: nobody => FrankSalad
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:4>
* owner: FrankSalad =>
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:5>
* owner: => limnick
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:6>
* Attachment "template_import_logging.diff" added.
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:7>
Comment (by limnick):
After some further digging it appears the django.template logger added in
the commit I originally referenced will capture exceptions bubbled through
this function, however it will also catch things like missing variables in
templates and expected fallthrough behavior. All of this is at a level of
DEBUG which seems appropriate.
In order to be able to log only unexpected exceptions, I'm proposing
adding WARNING level logging to any uncaught exceptions during import
templatetag rendering. See attached patch for changes and regression test.
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:8>
Comment (by limnick):
fot ease of review I've created a PR here:
https://github.com/django/django/pull/5285
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:9>
* needs_better_patch: 0 => 1
Comment:
Left some comment on the PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:10>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:11>
* stage: Accepted => Ready for checkin
Comment:
Given a docs review.
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:12>
* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted
Comment:
Left a few comments for improvement.
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:13>
* needs_better_patch: 1 => 0
Comment:
should be all cleaned up
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:14>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:15>
* needs_better_patch: 1 => 0
Comment:
Should be all cleaned up again. docs and isort are broken on CI right now,
but they're broken for all PRs and are not caused by my change.
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:16>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"392f64842f678b6e29a2e5fac65a586d9c9a57ff" 392f6484]:
{{{
#!CommitTicketReference repository=""
revision="392f64842f678b6e29a2e5fac65a586d9c9a57ff"
Fixed #25373 -- Added warning logging for exceptions during {% include %}
tag rendering.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:17>
Comment (by Tim Graham <timograham@…>):
In [changeset:"b1f60460661c8058c511bfb7364dca935c5951ed" b1f60460]:
{{{
#!CommitTicketReference repository=""
revision="b1f60460661c8058c511bfb7364dca935c5951ed"
Refs #25373 -- Doc'd logging of exceptions during {% include %} rendering.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:18>