Fixed #32131 -- Also check in debug mode if static file exists #13587
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The behaviour of
ManifestStaticFilesStorage
differs between debug andnon-debug mode when a referenced static file does not actually exist (or an
absolute path is used instead of a relative one).
The following code demonstrates the issue:
The root cause for the issue is that when the staticfiles are hashed Django puts
them into the manifest file ("staticfiles.json") with a relative path (i.e.
without a leading slash) and when trying to find the file with leading slash
it fails because it does not exist. When getting the URL in debug mode it just
joins the path to the
STATIC_URL
(in our case/static
) and we get the validurl
/static/path/to/a/file.png
so no error is being raised.This can cause trouble when all test systems are using
debug = True
and anincorrect static file path is only detected after deployment to the production
instance that uses
debug = False
.In order to fix the problem we should also check in debug mode whether the
referenced file really exists.
https://code.djangoproject.com/ticket/32131#ticket