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

[s3] Pass object parameters to head_object in exists #1451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion storages/backends/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,9 @@ def exists(self, name):
return False

name = self._normalize_name(clean_name(name))
params = _filter_download_params(self.get_object_parameters(name))
try:
self.connection.meta.client.head_object(Bucket=self.bucket_name, Key=name)
self.connection.meta.client.head_object(Bucket=self.bucket_name, Key=name, **params)
return True
except ClientError as err:
if err.response["ResponseMetadata"]["HTTPStatusCode"] == 404:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,18 @@ def test_storage_exists(self):
Key="file.txt",
)

def test_storage_exists_ssec(self):
params = {"SSECustomerKey": "xyz", "CacheControl": "never"}
self.storage.get_object_parameters = lambda name: params

self.storage.file_overwrite = False
self.assertTrue(self.storage.exists("file.txt"))
self.storage.connection.meta.client.head_object.assert_called_with(
Bucket=self.storage.bucket_name,
Key="file.txt",
SSECustomerKey="xyz"
)

def test_storage_exists_false(self):
self.storage.file_overwrite = False
self.storage.connection.meta.client.head_object.side_effect = ClientError(
Expand Down