Collectstatic Creates Empty Files
I'm trying to upgrade an app to Django 1.11, but experience issues with collectstatic. Old versions: django 1.8.17 django-storages 1.5.1 New versions: django 1.11.12 django-stora
Solution 1:
We've encountered the same issue.
The underlying problem, I think, has multiple issues / sources:
- The ManifestFilesMixin uses and reuses ContentFile objects for generating the hashed files and saves them multiple times. Without resetting the ContentFile objects (by calling .seek(0) on them).
- The S3BotoStorage saves these files, without checking if they are at the correct position. Compare this to FileSystemStorage: The files are always read through from the beginning by iterating over the .chuncks() of the file.
We worked around the empty-file-issue by overriding S3BotoStorage like this:
class PatchedS3StaticStorage(S3BotoStorage):
def _save(self, name, content):
if hasattr(content, 'seek') and hasattr(content, 'seekable') and content.seekable():
content.seek(0)
return super()._save(name, content)
In short, we seek to the beginning of the file before saving it.
Post a Comment for "Collectstatic Creates Empty Files"