Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty files on S3 after gzipping with Django 1.11 (s3boto) #367

Closed
melwas opened this issue Jul 26, 2017 · 4 comments
Closed

Empty files on S3 after gzipping with Django 1.11 (s3boto) #367

melwas opened this issue Jul 26, 2017 · 4 comments

Comments

@melwas
Copy link
Contributor

melwas commented Jul 26, 2017

In Django 1.11.x there was a change in collectstatic command (here).

I noticed that after upgrade there is an issue with files uploaded to S3 when GZIP is enabled. Some files (post-processed by ManifestFilesMixin and used in its manifest file) are uploaded as empty files.

I found that there is a potential issue with _compress_content method in S3Boto3Storage class.

Currently, the method looks like this:

zbuf = BytesIO()
zfile = GzipFile(mode='wb', compresslevel=6, fileobj=zbuf)
try:
    zfile.write(force_bytes(content.read()))
finally:
    zfile.close()
zbuf.seek(0)
return zbuf

When I use the storage and also use ManifestFilesMixin from Django the content.read() returns an empty bytes object. If I add content.seek(0) before everything works as expected.

When I revert to Django 1.10.7 everything also works as expected. When I disable gzipping the files are also uploaded correctly.

@melwas melwas changed the title Empty files on S3 after gzipping with Django 1.11 Empty files on S3 after gzipping with Django 1.11 (s3boto) Jul 26, 2017
@jschneier
Copy link
Owner

A failing test case would be very helpful here. From reading the linked to Django changelog backwards incompat log it reads as though you have an issue on your side although I might be misunderstanding it.

@melwas
Copy link
Contributor Author

melwas commented Jul 28, 2017

@jschneier I added a failing test with explanation :)

@jmichalicek
Copy link

Just confirming this issue. I ran into it and tracked it down very shortly after Django 1.11 was released, but got sidetracked and did not get it reported.

@jschneier
Copy link
Owner

Fixed in #373. Will release shortly.

nitely pushed a commit to satellogic/django-storages that referenced this issue Jul 30, 2018
nitely pushed a commit to satellogic/django-storages that referenced this issue Jul 30, 2018
nitely pushed a commit to satellogic/django-storages that referenced this issue Jul 30, 2018
snowlotus530 pushed a commit to snowlotus530/storages_django that referenced this issue Oct 3, 2021
ipyramiddev added a commit to ipyramiddev/storage-api-django that referenced this issue Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants