Skip to content

Commit

Permalink
S3Boto3: Fix ValueError I/O operation on closed file (#754)
Browse files Browse the repository at this point in the history
This commit fixed a bug in Django that was addressed in the 1.10 release. It then had the knock on effects of causing #382. Since this library only supports 1.11+ this can be safely reverted.

This reverts commit c73680e.

Closes #382.
  • Loading branch information
jschneier committed Sep 10, 2019
1 parent b1d8e82 commit 1cf9b59
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
12 changes: 0 additions & 12 deletions storages/backends/s3boto3.py
Expand Up @@ -488,18 +488,6 @@ def _save(self, name, content):
if self.preload_metadata:
self._entries[encoded_name] = obj

# If both `name` and `content.name` are empty or None, your request
# can be rejected with `XAmzContentSHA256Mismatch` error, because in
# `django.core.files.storage.Storage.save` method your file-like object
# will be wrapped in `django.core.files.File` if no `chunks` method
# provided. `File.__bool__` method is Django-specific and depends on
# file name, for this reason`botocore.handlers.calculate_md5` can fail
# even if wrapped file-like object exists. To avoid Django-specific
# logic, pass internal file-like object if `content` is `File`
# class instance.
if isinstance(content, File):
content = content.file

self._save_content(obj, content, parameters=parameters)
# Note: In boto3, after a put, last_modified is automatically reloaded
# the next time it is accessed; no need to specifically reload it.
Expand Down
8 changes: 4 additions & 4 deletions tests/test_s3boto3.py
Expand Up @@ -116,7 +116,7 @@ def test_storage_save(self):

obj = self.storage.bucket.Object.return_value
obj.upload_fileobj.assert_called_with(
content.file,
content,
ExtraArgs={
'ContentType': 'text/plain',
'ACL': self.storage.default_acl,
Expand All @@ -135,7 +135,7 @@ def test_storage_save_with_acl(self):

obj = self.storage.bucket.Object.return_value
obj.upload_fileobj.assert_called_with(
content.file,
content,
ExtraArgs={
'ContentType': 'text/plain',
'ACL': 'private',
Expand All @@ -154,7 +154,7 @@ def test_content_type(self):

obj = self.storage.bucket.Object.return_value
obj.upload_fileobj.assert_called_with(
content.file,
content,
ExtraArgs={
'ContentType': 'image/jpeg',
'ACL': self.storage.default_acl,
Expand All @@ -170,7 +170,7 @@ def test_storage_save_gzipped(self):
self.storage.save(name, content)
obj = self.storage.bucket.Object.return_value
obj.upload_fileobj.assert_called_with(
content.file,
content,
ExtraArgs={
'ContentType': 'application/octet-stream',
'ContentEncoding': 'gzip',
Expand Down

0 comments on commit 1cf9b59

Please sign in to comment.