From 3df7083aff1347a1b8e2afa81284484f5dfdf3a0 Mon Sep 17 00:00:00 2001 From: Harry Karvonen Date: Fri, 15 Jul 2022 16:06:36 +0300 Subject: [PATCH] gcloud: Use DEFAULT_RETRY when uploading a file. --- storages/backends/gcloud.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/storages/backends/gcloud.py b/storages/backends/gcloud.py index 3c0289082..7f9a82a09 100644 --- a/storages/backends/gcloud.py +++ b/storages/backends/gcloud.py @@ -19,6 +19,7 @@ from google.cloud.exceptions import NotFound from google.cloud.storage import Blob, Client from google.cloud.storage.blob import _quote + from google.cloud.storage.retry import DEFAULT_RETRY except ImportError: raise ImproperlyConfigured("Could not load Google Cloud Storage bindings.\n" "See https://github.com/GoogleCloudPlatform/gcloud-python") @@ -88,6 +89,7 @@ def close(self): blob_params = self._storage.get_object_parameters(self.name) self.blob.upload_from_file( self.file, rewind=True, content_type=self.mime_type, + retry=DEFAULT_RETRY, predefined_acl=blob_params.get('acl', self._storage.default_acl)) self._file.close() self._file = None @@ -187,7 +189,7 @@ def _save(self, name, content): for prop, val in blob_params.items(): setattr(file_object.blob, prop, val) - file_object.blob.upload_from_file(content, rewind=True, size=getattr(content, 'size', None), **upload_params) + file_object.blob.upload_from_file(content, rewind=True, retry=DEFAULT_RETRY, size=getattr(content, 'size', None), **upload_params) return cleaned_name def get_object_parameters(self, name):