[Django] #26164: Django 1.9: All template tags are loaded, whether desired or not

16 views
Skip to first unread message

Django

unread,
Feb 1, 2016, 5:44:52 PM2/1/16
to django-...@googlegroups.com
#26164: Django 1.9: All template tags are loaded, whether desired or not
---------------------------------+--------------------
Reporter: tBaxter | Owner: nobody
Type: Uncategorized | Status: new
Component: Template system | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------
In Django 1.9, anything in /app/templatetags/ appears to be loaded,
whether they are loaded into a template or not, desired, or even suited to
the current environment.

To reproduce:

1. Start a fresh Django 1.9 project
2. pip install typogrify
3. Create a TemplateView URL, and in the template, simply have "Hello
world", with no blocks, no template loading, no nothing.

You will see "ImportError raised when trying to load
'typogrify.templatetags.jinja_filters': No module named jinja2"

Because jinja2 was never pip installed, of course. But Django is loading
https://github.com/mintchaos/typogrify/blob/master/typogrify/templatetags/jinja_filters.py
anyway.

I don't think an unwanted third-party app should be able to control the
environment. If this *is* actually desired or necessary, whether it makes
sense to me or not, I think some guidance for template tag writers and
site owners to mitigate downsides is in order

Reference: https://github.com/mintchaos/typogrify/issues/44

--
Ticket URL: <https://code.djangoproject.com/ticket/26164>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 1, 2016, 5:49:13 PM2/1/16
to django-...@googlegroups.com
#26164: Django 1.9: All template tags are loaded, whether desired or not
---------------------------------+--------------------------------------

Reporter: tBaxter | Owner: nobody
Type: Uncategorized | Status: new
Component: Template system | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Maybe related to this commit:
https://github.com/django/django/commit/655f52491505932ef04264de2bce21a03f3a7cd0

--
Ticket URL: <https://code.djangoproject.com/ticket/26164#comment:1>

Django

unread,
Feb 1, 2016, 6:00:53 PM2/1/16
to django-...@googlegroups.com
#26164: Django 1.9: All template tags are loaded, whether desired or not
---------------------------------+--------------------------------------
Reporter: tBaxter | Owner: nobody
Type: Uncategorized | Status: closed

Component: Template system | Version: 1.9
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed

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

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

* status: new => closed
* resolution: => invalid


Comment:

Yes, this is intentional. See the section "Template tag modules are
imported when templates are configured" added in the backwards-
incompatible section of the 1.9 release notes in that commit.

--
Ticket URL: <https://code.djangoproject.com/ticket/26164#comment:2>

Django

unread,
Feb 2, 2016, 9:22:36 AM2/2/16
to django-...@googlegroups.com
#26164: Django 1.9: All template tags are loaded, whether desired or not
---------------------------------+--------------------------------------
Reporter: tBaxter | Owner: nobody
Type: Uncategorized | Status: closed

Component: Template system | Version: 1.9
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed

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

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by tBaxter):

Respectfully, I think at the very least there's a documentation
improvement to be made here. The single sentence "Template tag modules are
imported when templates are configured" falls well short of describing the
current behavior, which was was surprising to many experienced Django devs
on #django IRC.

I understand that it is intentional, and whether or not I agree it's the
correct behavior isn't particularly relevant, but I'm trying to at least
minimize surprises and unwanted side-effects.

I would also like to propose a TEMPLATE['exclude_tags'] = () type setting
in which one could add filenames that should explicitly be blocked and
never loaded, if they are unwanted. I understand that could get a bit
messy and convoluted, but I wanted to float the idea.

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

Django

unread,
Feb 2, 2016, 9:32:35 AM2/2/16
to django-...@googlegroups.com
#26164: Django 1.9: All template tags are loaded, whether desired or not
---------------------------------+--------------------------------------
Reporter: tBaxter | Owner: nobody
Type: Uncategorized | Status: closed

Component: Template system | Version: 1.9
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed

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

Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by timgraham):

Feel free to propose a documentation patch for the release notes.

Regarding the proposed setting, I think it's more convenient for users if
third-party apps adapt their code to raise errors lazily if they want the
old behavior rather than requiring users of the app to add certain
template tag modules to an exclude setting. Feel free to raise the
proposal on the DevelopersMailingList if you disagree.

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

Reply all
Reply to author
Forward
0 new messages