Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#24813 closed Cleanup/optimization (fixed)

Document that {% include %} suppresses errors when DEBUG=False

Reported by: Pratyush Mittal Owned by: andrei kulakov
Component: Documentation Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

It seems that the TemplateDoesNotExist error is not raised in Django 1.8 tests. Adding {% include "MissingTemplate.html" %} in templates will pass the tests without an error, though it will raise an error on manual browsing.

Demo Code: https://github.com/pratyushmittal/DummyProject

I have provided an example testcase above. In the DummyProject, running python manage.py test should pass the tests, while python manage.py runserver and opening 127.0.0.1:8000 should raise a TemplateDoesNotExist error.

Change History (10)

comment:1 by Andriy Sokolovskiy, 9 years ago

Checked on built-in django template engine, error is not rising.
Got TemplateNotFound on jinja2.

Seems to be a bug.

comment:2 by Pratyush Mittal, 9 years ago

It seems that include template tag is altogether being skipped in the tests in Django 1.8.

comment:3 by Tim Graham, 9 years ago

Component: Testing frameworkDocumentation
Summary: TemplateDoesNotExist is not raised in testsDocument that {% include %} suppresses errors when DEBUG=False
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

Django tests run with DEBUG=False. In this case, template tag exceptions are often suppressed. It might be worth adding a note to the {% include %} documentation that the tag will render as an empty string if rendering the included template raises an exception.

comment:4 by Andriy Sokolovskiy, 9 years ago

In this case, template tag exceptions are often suppressed

Seems that other template engines should have the same behaviour.

comment:5 by Tim Graham, 9 years ago

I'm not sure what you have in mind, but it doesn't make sense to me that we can enforce design decisions of the Django template language onto other templating languages. In particular, the relevant documentation can be found in the custom template tags docs:

render() should generally fail silently, particularly in a production environment. In some cases however, particularly if context.template.engine.debug is True, this method may raise an exception to make debugging easier. For example, several core tags raise django.template.TemplateSyntaxError if they receive the wrong number or type of arguments.

comment:6 by andrei kulakov, 9 years ago

Owner: changed from nobody to andrei kulakov
Status: newassigned

comment:7 by Tim Graham, 9 years ago

Has patch: set
Patch needs improvement: set

PR (with comments for improvement).

comment:8 by Tim Graham, 9 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:9 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In fc3409b0:

Fixed #24813 -- Documented {% include %} debug behavior variance

comment:10 by Tim Graham <timograham@…>, 9 years ago

In 5a0e39b:

[1.8.x] Fixed #24813 -- Documented {% include %} debug behavior variance

Backport of fc3409b0932959f2aca42715e9147113d0e40f79 from master

Note: See TracTickets for help on using tickets.
Back to Top