[Django] #25373: Django Admin silently catches exceptions without a chance to log them

19 views
Skip to first unread message

Django

unread,
Sep 9, 2015, 2:37:58 PM9/9/15
to django-...@googlegroups.com
#25373: Django Admin silently catches exceptions without a chance to log them
-------------------------------+--------------------
Reporter: limnick | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------
Exceptions raised from ModelAdmin fields during the rendering of the admin
detail view for a model are silently caught and there's no simple way to
log them without putting the template renderer in debug mode.

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.

Django

unread,
Sep 9, 2015, 2:42:13 PM9/9/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: nobody
Type: New feature | 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 timgraham):

* 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>

Django

unread,
Sep 9, 2015, 5:43:47 PM9/9/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: nobody

Type: New feature | 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
---------------------------------+------------------------------------

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>

Django

unread,
Sep 9, 2015, 7:30:28 PM9/9/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: nobody

Type: New feature | 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
---------------------------------+------------------------------------

Comment (by timgraham):

I didn't have an alternate implementation in mind.

--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:3>

Django

unread,
Sep 10, 2015, 3:58:56 PM9/10/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+--------------------------------------
Reporter: limnick | Owner: FrankSalad
Type: New feature | Status: assigned

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 FrankSalad):

* owner: nobody => FrankSalad
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:4>

Django

unread,
Sep 10, 2015, 3:59:32 PM9/10/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner:

Type: New feature | 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 FrankSalad):

* owner: FrankSalad =>
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:5>

Django

unread,
Sep 11, 2015, 7:33:31 PM9/11/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: limnick

Type: New feature | Status: assigned
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 limnick):

* owner: => limnick


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:6>

Django

unread,
Sep 11, 2015, 7:37:06 PM9/11/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: limnick
Type: New feature | Status: assigned
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 limnick):

* Attachment "template_import_logging.diff" added.

Django

unread,
Sep 11, 2015, 7:37:59 PM9/11/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: limnick
Type: New feature | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by limnick):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:7>

Django

unread,
Sep 11, 2015, 7:40:42 PM9/11/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: limnick
Type: New feature | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

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>

Django

unread,
Sep 14, 2015, 1:26:02 PM9/14/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: limnick
Type: New feature | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

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>

Django

unread,
Sep 14, 2015, 7:42:31 PM9/14/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: limnick
Type: New feature | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by charettes):

* needs_better_patch: 0 => 1


Comment:

Left some comment on the PR.

--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:10>

Django

unread,
Sep 14, 2015, 8:44:07 PM9/14/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: limnick
Type: New feature | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by limnick):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:11>

Django

unread,
Sep 16, 2015, 5:00:43 PM9/16/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
-------------------------------------+-------------------------------------

Reporter: limnick | Owner: limnick
Type: New feature | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* stage: Accepted => Ready for checkin


Comment:

Given a docs review.

--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:12>

Django

unread,
Sep 18, 2015, 8:59:44 AM9/18/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------

Reporter: limnick | Owner: limnick
Type: New feature | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by timgraham):

* 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>

Django

unread,
Sep 18, 2015, 5:20:06 PM9/18/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: limnick
Type: New feature | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by limnick):

* needs_better_patch: 1 => 0


Comment:

should be all cleaned up

--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:14>

Django

unread,
Sep 19, 2015, 6:57:57 PM9/19/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: limnick
Type: New feature | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25373#comment:15>

Django

unread,
Sep 21, 2015, 4:52:06 PM9/21/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: limnick
Type: New feature | Status: assigned
Component: Template system | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by limnick):

* 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>

Django

unread,
Sep 21, 2015, 8:02:32 PM9/21/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: limnick
Type: New feature | Status: closed

Component: Template system | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* 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>

Django

unread,
Sep 23, 2015, 11:53:10 AM9/23/15
to django-...@googlegroups.com
#25373: Add logging for {% include %} exceptions when template.debug = False
---------------------------------+------------------------------------
Reporter: limnick | Owner: limnick
Type: New feature | Status: closed
Component: Template system | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages