#25373 closed New feature (fixed)
Add logging for {% include %} exceptions when template.debug = False
Reported by: | Nick Johnson | Owned by: | Nick Johnson |
---|---|---|---|
Component: | Template system | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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 this change:
The problematic exception catching line is here
Attachments (1)
Change History (19)
comment:1 by , 9 years ago
Component: | contrib.admin → Template system |
---|---|
Easy pickings: | unset |
Summary: | Django Admin silently catches exceptions without a chance to log them → Add logging for {% include %} exceptions when template.debug = False |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → New feature |
comment:2 by , 9 years ago
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
comment:4 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 9 years ago
Owner: | removed |
---|---|
Status: | assigned → new |
comment:6 by , 9 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
by , 9 years ago
Attachment: | template_import_logging.diff added |
---|
comment:7 by , 9 years ago
Has patch: | set |
---|
comment:8 by , 9 years ago
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.
comment:9 by , 9 years ago
fot ease of review I've created a PR here: https://github.com/django/django/pull/5285
comment:11 by , 9 years ago
Patch needs improvement: | unset |
---|
comment:13 by , 9 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Ready for checkin → Accepted |
Left a few comments for improvement.
comment:15 by , 9 years ago
Patch needs improvement: | set |
---|
comment:16 by , 9 years ago
Patch needs improvement: | unset |
---|
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.
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: