﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32131	ManifestStaticFilesStorage should also check in debug mode whether referenced file actually exists	Fabian Köster	nobody	"We just had a case where we referenced a static file somewhere in the code like this

{{{#!python
from django.templatetags.static import static
static(""/path/to/a/file.png"")
}}}

This worked perfectly fine on the development system and also on the staging systems. After deployment to the production system we noticed that it does not work when debug mode is disabled (`debug = False`) and the staticfiles are searched using the staticfiles.json manifest. In the code above we used an absolute path to the file whereas in the manifest all files are given with their relative path.

The following code can be used to reproduce the problem (using force=True is equivalent to debug=False in this case):

{{{#!python
from django.contrib.staticfiles.storage import ManifestStaticFilesStorage
>>> ManifestStaticFilesStorage().url(""path/to/a/file.png"")
'/static/path/to/a/file.png'
>>> ManifestStaticFilesStorage().url(""/path/to/a/file.png"")
'/static/path/to/a/file.png'
>>> ManifestStaticFilesStorage().url(""path/to/a/file.png"", force=True)
'/static/path/to/a/file.f208556b8835.png'
>>> ManifestStaticFilesStorage().url(""/path/to/a/file.png"", force=True)
Traceback (most recent call last):
  File ""<input>"", line 1, in <module>
    ManifestStaticFilesStorage().url('/path/to/a/file.png', force=True)
  File ""/app/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/contrib/staticfiles/storage.py"", line 153, in url
    return self._url(self.stored_name, name, force)
  File ""/app/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/contrib/staticfiles/storage.py"", line 132, in _url
    hashed_name = hashed_name_func(*args)
  File ""/app/.pyenv/versions/3.7.2/lib/python3.7/site-packages/django/contrib/staticfiles/storage.py"", line 420, in stored_name
    raise ValueError(""Missing staticfiles manifest entry for '%s'"" % clean_name)
ValueError: Missing staticfiles manifest entry for '/path/to/a/file.png'
}}}

I think the behaviour should be the same regardless if debug is `True` or `False`. I therefore propose to add a check to the `debug = True` code path that checks for the existance of the file as well so when referencing a non-existing file or giving an absolute path raises the same exception as it would on the production system with `debug = False`. I will create a PR for this in a few minutes."	Bug	closed	contrib.staticfiles	3.1	Normal	wontfix		Markus Bertheau	Unreviewed	0	0	0	0	0	0
