I'm using the Azure storage for static files and using Django's ManifestFilesMixin so that files have a unique hash. The problem I'm running into is that the read_manifest method handles the case where the manifest is missing which should always happen the very first time you run collectstatic (you haven't written the manifest to Azure yet) by catching an IOError. However, the Azure libraries raise AzureMissingResourceHttpError which is not a subclass of IOError. As a result, this error bubbles up.
You could definitely make the argument that the Azure Python libraries should be changed to make an exception they raise when reading a remote file a subclass of IOError. Nonetheless, I'm going to file this issue here first as it is definitely an issue of compatibility between Django storage and Azure.
I'm using Django 1.11.16 and django-storage 1.7.1.
I'm using the following workaround to workaround this issue:
from django.contrib.staticfiles.storage import ManifestFilesMixin
from storages.backends.azure_storage import AzureStorage
from azure.common import AzureMissingResourceHttpError
class AzureStaticStorage(ManifestFilesMixin, AzureStorage):
"""
An Azure Storage backend for static media
* Uses Django's ManifestFilesMixin to have unique file paths (eg. core.a6f5e2c.css)
"""
azure_container = 'static'
def read_manifest(self):
"""Handle a workaround to make Azure work with Django on the first 'collectstatic'"""
try:
return super(AzureStaticStorage, self).read_manifest()
except AzureMissingResourceHttpError:
return None
This also seems to be happening for the S3 storage on first collectstatic
Yes, big pain for S3
My S3 hotfix
class StaticFileStorage(S3Boto3Storage):
def read_manifest(self):
try:
with self.open(self.manifest_name) as manifest:
return manifest.read().decode()
except (FileNotFoundError, IOError):
return None
Most helpful comment
Yes, big pain for S3
My S3 hotfix