[Django] #18225: Staticfiles template tag does not fail silently

16 views
Skip to first unread message

Django

unread,
Apr 28, 2012, 4:22:57 AM4/28/12
to django-...@googlegroups.com
#18225: Staticfiles template tag does not fail silently
-------------------------------------+--------------------
Reporter: bouke | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 1.4
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+--------------------
Last night we had a major outage on our site, due to a missing static
file. We used `{% static 'css/fancybox.jquery.css' %}` in our base
template, but that file had gone missing. As there were some caches
involved, the problem presented only a few hours later when the caches
expired. From what I understand is that template tags should fail silently
as per the docs:
[[BR]]
[[BR]]

> render() should never raise TemplateSyntaxError or any other exception.
It should fail silently, just as template filters should.
[[BR]]


So I was surprised that instead of failing silently, the template tag
raised an exception (and brought the whole site to a stop). I think the
template tag should fail silently instead of raising the exception.

{{{
File "app/local/lib/python2.7/site-
packages/django/core/handlers/base.py", line 136, in get_response
response = response.render()

File "app/local/lib/python2.7/site-packages/django/template/response.py",
line 104, in render
self._set_content(self.rendered_content)

File "app/local/lib/python2.7/site-packages/django/template/response.py",
line 81, in rendered_content
content = template.render(context)

File "app/local/lib/python2.7/site-packages/django/template/base.py",
line 140, in render
return self._render(context)

File "app/local/lib/python2.7/site-packages/django/template/base.py",
line 134, in _render
return self.nodelist.render(context)

File "app/local/lib/python2.7/site-packages/django/template/base.py",
line 823, in render
bit = self.render_node(node, context)

File "app/local/lib/python2.7/site-packages/django/template/base.py",
line 837, in render_node
return node.render(context)

File "app/local/lib/python2.7/site-
packages/django/template/loader_tags.py", line 123, in render
return compiled_parent._render(context)

File "app/local/lib/python2.7/site-packages/django/template/base.py",
line 134, in _render
return self.nodelist.render(context)

File "app/local/lib/python2.7/site-packages/django/template/base.py",
line 823, in render
bit = self.render_node(node, context)

File "app/local/lib/python2.7/site-packages/django/template/base.py",
line 837, in render_node
return node.render(context)

File "app/local/lib/python2.7/site-packages/django/template/base.py",
line 1107, in render
return func(*resolved_args, **resolved_kwargs)

File "app/local/lib/python2.7/site-
packages/django/contrib/staticfiles/templatetags/staticfiles.py", line 13,
in static
return staticfiles_storage.url(path)

File "app/config/storages.py", line 40, in url
url = super(StaticStorage, self).url(name, force)

File "app/local/lib/python2.7/site-
packages/django/contrib/staticfiles/storage.py", line 114, in url
hashed_name = self.hashed_name(clean_name).replace('\\', '/')

File "app/local/lib/python2.7/site-
packages/django/contrib/staticfiles/storage.py", line 74, in hashed_name
(clean_name, self))

ValueError: The file 'styles/jquery.fancybox.css' could not be found with
<config.storages.StaticStorage object at 0x36fee90>.
}}}

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

Django

unread,
May 1, 2012, 10:02:45 PM5/1/12
to django-...@googlegroups.com
#18225: Staticfiles template tag does not fail silently
-------------------------------------+------------------------------------
Reporter: bouke | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by moritzs):

* needs_docs: => 0
* needs_better_patch: => 0
* needs_tests: => 0
* easy: 0 => 1
* stage: Unreviewed => Accepted


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

Django

unread,
May 2, 2012, 7:08:01 AM5/2/12
to django-...@googlegroups.com
#18225: Staticfiles template tag does not fail silently
-------------------------------------+------------------------------------
Reporter: bouke | Owner: moritzs
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by moritzs):

* status: new => assigned
* cc: moritz.sichert@… (added)
* owner: nobody => moritzs


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

Django

unread,
May 2, 2012, 3:25:07 PM5/2/12
to django-...@googlegroups.com
#18225: Staticfiles template tag does not fail silently
-------------------------------------+------------------------------------
Reporter: bouke | Owner: moritzs
Type: Bug | Status: assigned
Component: contrib.staticfiles | Version: 1.4
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by moritzs):

* has_patch: 0 => 1


Comment:

Added patch ([https://github.com/django/django/pull/37 Github Pull
Request])

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

Django

unread,
May 10, 2012, 11:56:08 AM5/10/12
to django-...@googlegroups.com
#18225: Staticfiles template tag does not fail silently
-------------------------------------+------------------------------------
Reporter: bouke | Owner: moritzs
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 1.4
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by jezdez):

* status: assigned => closed
* resolution: => wontfix


Comment:

First of all, please don't accept your own tickets, we have a community of
ticket triagers that didn't have a chance to see this ticket since you
didn't leave it at the Unreviewed state.

Secondly, I'm sorry but this isn't Django's fault, if you're missing a
file, it's good to raise an exception. You quoted a part of the
documentation of how to write the render method of custom template tags,
not how template tags should work in general. It is an error to refer to a
file with the staticfiles' static template tag as it uses a storage
backend to calculate the URL of the static files. If you just want to
generate a URL that is concatenated with STATIC_URL, use the core static
template tag:
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#std
:templatetag-static

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

Django

unread,
Apr 26, 2014, 10:34:01 PM4/26/14
to django-...@googlegroups.com
#18225: Staticfiles template tag does not fail silently
-------------------------------------+------------------------------------
Reporter: bouke | Owner: moritzs
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 1.4

Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by anon0405@…):

It would be nice if there were a setting that toggled whether this fails
loudly or silently -- often it is better to serve an html file with broken
formatting (missing css), missing functionality (missing js), or missing
niceties (missing .ico) than to throw up a server error and prevent any
information from reaching the end user.

Especially where the behavior of {% static %} is explicitly to not raise
errors in development, the current behavior creates time bombs that are
out of step with the rest of django's template error philosophy -- fail
silently whenever possible.

Two options are:
* {% static 'file/path.stuff' True %} -- passing an optional parameter of
whether to fail silently, so this can be turned on/off as needed
* STATIC_TAG_FAILS_SILENTLY=True -- an option in settings.py

If there isn't a way to make it fail silently in production, then the
errors should somehow be raised in DEV so they are caught and fixed.

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

Reply all
Reply to author
Forward
0 new messages