From f07d7e0a73a9961de91de30292096d68497ee473 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 18 Feb 2019 14:27:28 -0500 Subject: [PATCH] Remove the HEAD check for a file being read in cloud storage In addition to being unnecessary, it also causes read-after-write issues occasionally on S3 --- storage/cloud.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/storage/cloud.py b/storage/cloud.py index 74d205bf3..04bd8477c 100644 --- a/storage/cloud.py +++ b/storage/cloud.py @@ -114,9 +114,15 @@ class _CloudStorage(BaseStorageV2): self._initialize_cloud_conn() path = self._init_path(path) key = self._key_class(self._cloud_bucket, path) - if not key.exists(): - raise IOError('No such key: \'{0}\''.format(path)) - return key.get_contents_as_string() + try: + return key.get_contents_as_string() + except S3ResponseError as s3r: + # Raise an IOError in case the key was not found, to maintain the current + # interface. + if s3r.error_code == 'NoSuchKey': + raise IOError('No such key: \'{0}\''.format(path)) + + raise def put_content(self, path, content): self._initialize_cloud_conn()