#30327 closed Bug (invalid)

Failing collectstatic with ManifestFilesMixin

Reported by: Gadir Rustamli Owned by: Gadir Rustamli
Component: contrib.staticfiles Version: 2.2
Severity: Normal Keywords: staticfiles versioning
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Collectstatic throws KeyError: 'ContentLength' when used with ManifestFileMixin. Below is the custom storage class I've written to upload the files to Google Cloud Storage.

class CustomStorage(ManifestFilesMixin, S3Boto3Storage):
         pass

in the settings.py

    STATICFILES_STORAGE = 'myapp.storage.CustomStorage'

And here is the stacktrace:

UserWarning: The default behavior of S3Boto3Storage is insecure and will change in django-storages 2.0. By default files and new buckets are saved with an ACL of 'public-read' (globally publicly readable). Version 2.0 will default to using the bucket's ACL. To opt into the new behavior set AWS_DEFAULT_ACL = None, otherwise to silence this warning explicitly set AWS_DEFAULT_ACL.
  "The default behavior of S3Boto3Storage is insecure and will change "
Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 188, in handle
    collected = self.collect()
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 128, in collect
    for original_path, processed_path, processed in processor:
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 402, in post_process
    yield from super().post_process(*args, **kwargs)
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 236, in post_process
    for name, hashed_name, processed, _ in self._post_process(paths, adjustable_paths, hashed_files):
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 293, in _post_process
    content = pattern.sub(converter, content)
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 194, in converter
    force=True, hashed_files=hashed_files,
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 131, in _url
    hashed_name = hashed_name_func(*args)
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 342, in _stored_name
    cache_name = self.clean_name(self.hashed_name(name))
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 99, in hashed_name
    file_hash = self.file_hash(clean_name, content)
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py", line 79, in file_hash
    for chunk in content.chunks():
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/core/files/base.py", line 55, in chunks
    self.seek(0)
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/django/core/files/utils.py", line 20, in <lambda>
    seek = property(lambda self: self.file.seek)
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/storages/backends/s3boto3.py", line 97, in _get_file
    self.obj.download_fileobj(self._file)
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/boto3/s3/inject.py", line 760, in object_download_fileobj
    ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/boto3/s3/inject.py", line 678, in download_fileobj
    return future.result()
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/s3transfer/futures.py", line 106, in result
    return self._coordinator.result()
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/s3transfer/futures.py", line 265, in result
    raise self._exception
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/s3transfer/tasks.py", line 255, in _main
    self._submit(transfer_future=transfer_future, **kwargs)
  File "/home/ufaz/webapps/ufaz_website/.venv/lib/python3.6/site-packages/s3transfer/download.py", line 348, in _submit
    response['ContentLength'])
KeyError: 'ContentLength'

As a reminder. I am using Google Cloud Storage since it is also S3 compatible

Change History (2)

comment:1 Changed 16 months ago by Gadir Rustamli

Owner: changed from nobody to Gadir Rustamli
Status: newassigned

comment:2 Changed 16 months ago by felixxm

Resolution: invalid
Severity: Release blockerNormal
Status: assignedclosed

This is not a bug in Django itself. S3Boto3Storage or ManifestFilesMixin are not provided by Django. It looks like a typo in s3transfer package, i.e. ContentLength instead of Content-Length.

Note: See TracTickets for help on using tickets.
Back to Top