Skip to content

Commit

Permalink
Fix: Remove deprecated num_retries argument (#1377)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsg committed Dec 5, 2024
1 parent 1b98fb2 commit f77ba4e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 447 deletions.
23 changes: 3 additions & 20 deletions google/cloud/storage/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@
("if_source_metageneration_not_match", "ifSourceMetagenerationNotMatch"),
)

_NUM_RETRIES_MESSAGE = (
"`num_retries` has been deprecated and will be removed in a future "
"release. Use the `retry` argument with a Retry or ConditionalRetryPolicy "
"object, or None, instead."
)

# _NOW() returns the current local date and time.
# It is preferred to use timezone-aware datetimes _NOW(_UTC),
# which returns the current UTC date and time.
Expand Down Expand Up @@ -634,36 +628,25 @@ def _bucket_bound_hostname_url(host, scheme=None):
return f"{scheme}://{host}"


def _api_core_retry_to_resumable_media_retry(retry, num_retries=None):
def _api_core_retry_to_resumable_media_retry(retry):
"""Convert google.api.core.Retry to google.cloud.storage._media.RetryStrategy.
Custom predicates are not translated.
:type retry: google.api_core.Retry
:param retry: (Optional) The google.api_core.Retry object to translate.
:type num_retries: int
:param num_retries: (Optional) The number of retries desired. This is
supported for backwards compatibility and is mutually exclusive with
`retry`.
:rtype: google.cloud.storage._media.RetryStrategy
:returns: A RetryStrategy with all applicable attributes copied from input,
or a RetryStrategy with max_retries set to 0 if None was input.
:returns: A RetryStrategy with all applicable attributes copied from input.
"""

if retry is not None and num_retries is not None:
raise ValueError("num_retries and retry arguments are mutually exclusive")

elif retry is not None:
if retry is not None:
return _media.RetryStrategy(
max_sleep=retry._maximum,
max_cumulative_retry=retry._deadline,
initial_delay=retry._initial,
multiplier=retry._multiplier,
)
elif num_retries is not None:
return _media.RetryStrategy(max_retries=num_retries)
else:
return _media.RetryStrategy(max_retries=0)

Expand Down
112 changes: 2 additions & 110 deletions google/cloud/storage/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
from google.cloud.storage._helpers import _get_default_storage_base_url
from google.cloud.storage._signing import generate_signed_url_v2
from google.cloud.storage._signing import generate_signed_url_v4
from google.cloud.storage._helpers import _NUM_RETRIES_MESSAGE
from google.cloud.storage._helpers import _API_VERSION
from google.cloud.storage._helpers import _virtual_hosted_style_base_url
from google.cloud.storage._opentelemetry_tracing import create_trace_span
Expand Down Expand Up @@ -1863,7 +1862,6 @@ def _do_multipart_upload(
stream,
content_type,
size,
num_retries,
predefined_acl,
if_generation_match,
if_generation_not_match,
Expand Down Expand Up @@ -1900,15 +1898,6 @@ def _do_multipart_upload(
``stream``). If not provided, the upload will be concluded once
``stream`` is exhausted (or :data:`None`).
:type num_retries: int
:param num_retries:
Number of upload retries. By default, only uploads with
if_generation_match set will be retried, as uploads without the
argument are not guaranteed to be idempotent. Setting num_retries
will override this default behavior and guarantee retries even when
if_generation_match is not set. (Deprecated: This argument
will be removed in a future release.)
:type predefined_acl: str
:param predefined_acl: (Optional) Predefined access control list
Expand Down Expand Up @@ -2023,9 +2012,7 @@ def _do_multipart_upload(
upload_url = _add_query_parameters(base_url, name_value_pairs)
upload = MultipartUpload(upload_url, headers=headers, checksum=checksum)

upload._retry_strategy = _api_core_retry_to_resumable_media_retry(
retry, num_retries
)
upload._retry_strategy = _api_core_retry_to_resumable_media_retry(retry)

extra_attributes = {
"url.full": upload_url,
Expand All @@ -2050,7 +2037,6 @@ def _initiate_resumable_upload(
stream,
content_type,
size,
num_retries,
predefined_acl=None,
extra_headers=None,
chunk_size=None,
Expand Down Expand Up @@ -2092,15 +2078,6 @@ def _initiate_resumable_upload(
:type predefined_acl: str
:param predefined_acl: (Optional) Predefined access control list
:type num_retries: int
:param num_retries:
Number of upload retries. By default, only uploads with
if_generation_match set will be retried, as uploads without the
argument are not guaranteed to be idempotent. Setting num_retries
will override this default behavior and guarantee retries even when
if_generation_match is not set. (Deprecated: This argument
will be removed in a future release.)
:type extra_headers: dict
:param extra_headers:
(Optional) Extra headers to add to standard headers.
Expand Down Expand Up @@ -2230,9 +2207,7 @@ def _initiate_resumable_upload(
upload_url, chunk_size, headers=headers, checksum=checksum
)

upload._retry_strategy = _api_core_retry_to_resumable_media_retry(
retry, num_retries
)
upload._retry_strategy = _api_core_retry_to_resumable_media_retry(retry)

upload.initiate(
transport,
Expand All @@ -2252,7 +2227,6 @@ def _do_resumable_upload(
stream,
content_type,
size,
num_retries,
predefined_acl,
if_generation_match,
if_generation_not_match,
Expand Down Expand Up @@ -2292,15 +2266,6 @@ def _do_resumable_upload(
``stream``). If not provided, the upload will be concluded once
``stream`` is exhausted (or :data:`None`).
:type num_retries: int
:param num_retries:
Number of upload retries. By default, only uploads with
if_generation_match set will be retried, as uploads without the
argument are not guaranteed to be idempotent. Setting num_retries
will override this default behavior and guarantee retries even when
if_generation_match is not set. (Deprecated: This argument
will be removed in a future release.)
:type predefined_acl: str
:param predefined_acl: (Optional) Predefined access control list
Expand Down Expand Up @@ -2365,7 +2330,6 @@ def _do_resumable_upload(
stream,
content_type,
size,
num_retries,
predefined_acl=predefined_acl,
if_generation_match=if_generation_match,
if_generation_not_match=if_generation_not_match,
Expand Down Expand Up @@ -2403,7 +2367,6 @@ def _do_upload(
stream,
content_type,
size,
num_retries,
predefined_acl,
if_generation_match,
if_generation_not_match,
Expand Down Expand Up @@ -2444,15 +2407,6 @@ def _do_upload(
``stream``). If not provided, the upload will be concluded once
``stream`` is exhausted (or :data:`None`).
:type num_retries: int
:param num_retries:
Number of upload retries. By default, only uploads with
if_generation_match set will be retried, as uploads without the
argument are not guaranteed to be idempotent. Setting num_retries
will override this default behavior and guarantee retries even when
if_generation_match is not set. (Deprecated: This argument
will be removed in a future release.)
:type predefined_acl: str
:param predefined_acl: (Optional) Predefined access control list
Expand Down Expand Up @@ -2542,7 +2496,6 @@ def _do_upload(
stream,
content_type,
size,
num_retries,
predefined_acl,
if_generation_match,
if_generation_not_match,
Expand All @@ -2559,7 +2512,6 @@ def _do_upload(
stream,
content_type,
size,
num_retries,
predefined_acl,
if_generation_match,
if_generation_not_match,
Expand All @@ -2579,7 +2531,6 @@ def _prep_and_do_upload(
rewind=False,
size=None,
content_type=None,
num_retries=None,
client=None,
predefined_acl=None,
if_generation_match=None,
Expand Down Expand Up @@ -2637,15 +2588,6 @@ def _prep_and_do_upload(
:type content_type: str
:param content_type: (Optional) Type of content being uploaded.
:type num_retries: int
:param num_retries:
Number of upload retries. By default, only uploads with
if_generation_match set will be retried, as uploads without the
argument are not guaranteed to be idempotent. Setting num_retries
will override this default behavior and guarantee retries even when
if_generation_match is not set. (Deprecated: This argument
will be removed in a future release.)
:type client: :class:`~google.cloud.storage.client.Client`
:param client:
(Optional) The client to use. If not passed, falls back to the
Expand Down Expand Up @@ -2719,14 +2661,6 @@ def _prep_and_do_upload(
:raises: :class:`~google.cloud.exceptions.GoogleCloudError`
if the upload response returns an error status.
"""
if num_retries is not None:
warnings.warn(_NUM_RETRIES_MESSAGE, DeprecationWarning, stacklevel=2)
# num_retries and retry are mutually exclusive. If num_retries is
# set and retry is exactly the default, then nullify retry for
# backwards compatibility.
if retry is DEFAULT_RETRY_IF_GENERATION_SPECIFIED:
retry = None

_maybe_rewind(file_obj, rewind=rewind)
predefined_acl = ACL.validate_predefined(predefined_acl)

Expand All @@ -2736,7 +2670,6 @@ def _prep_and_do_upload(
file_obj,
content_type,
size,
num_retries,
predefined_acl,
if_generation_match,
if_generation_not_match,
Expand All @@ -2758,7 +2691,6 @@ def upload_from_file(
rewind=False,
size=None,
content_type=None,
num_retries=None,
client=None,
predefined_acl=None,
if_generation_match=None,
Expand Down Expand Up @@ -2815,15 +2747,6 @@ def upload_from_file(
:type content_type: str
:param content_type: (Optional) Type of content being uploaded.
:type num_retries: int
:param num_retries:
Number of upload retries. By default, only uploads with
if_generation_match set will be retried, as uploads without the
argument are not guaranteed to be idempotent. Setting num_retries
will override this default behavior and guarantee retries even when
if_generation_match is not set. (Deprecated: This argument
will be removed in a future release.)
:type client: :class:`~google.cloud.storage.client.Client`
:param client:
(Optional) The client to use. If not passed, falls back to the
Expand Down Expand Up @@ -2887,7 +2810,6 @@ def upload_from_file(
rewind=rewind,
size=size,
content_type=content_type,
num_retries=num_retries,
client=client,
predefined_acl=predefined_acl,
if_generation_match=if_generation_match,
Expand Down Expand Up @@ -2928,7 +2850,6 @@ def upload_from_filename(
self,
filename,
content_type=None,
num_retries=None,
client=None,
predefined_acl=None,
if_generation_match=None,
Expand Down Expand Up @@ -2977,15 +2898,6 @@ def upload_from_filename(
(Optional) The client to use. If not passed, falls back to the
``client`` stored on the blob's bucket.
:type num_retries: int
:param num_retries:
Number of upload retries. By default, only uploads with
if_generation_match set will be retried, as uploads without the
argument are not guaranteed to be idempotent. Setting num_retries
will override this default behavior and guarantee retries even when
if_generation_match is not set. (Deprecated: This argument
will be removed in a future release.)
:type predefined_acl: str
:param predefined_acl: (Optional) Predefined access control list
Expand Down Expand Up @@ -3040,7 +2952,6 @@ def upload_from_filename(
self._handle_filename_and_upload(
filename,
content_type=content_type,
num_retries=num_retries,
client=client,
predefined_acl=predefined_acl,
if_generation_match=if_generation_match,
Expand All @@ -3057,7 +2968,6 @@ def upload_from_string(
self,
data,
content_type="text/plain",
num_retries=None,
client=None,
predefined_acl=None,
if_generation_match=None,
Expand Down Expand Up @@ -3093,15 +3003,6 @@ def upload_from_string(
(Optional) Type of content being uploaded. Defaults to
``'text/plain'``.
:type num_retries: int
:param num_retries:
Number of upload retries. By default, only uploads with
if_generation_match set will be retried, as uploads without the
argument are not guaranteed to be idempotent. Setting num_retries
will override this default behavior and guarantee retries even when
if_generation_match is not set. (Deprecated: This argument
will be removed in a future release.)
:type client: :class:`~google.cloud.storage.client.Client`
:param client:
(Optional) The client to use. If not passed, falls back to the
Expand Down Expand Up @@ -3163,7 +3064,6 @@ def upload_from_string(
file_obj=string_buffer,
size=len(data),
content_type=content_type,
num_retries=num_retries,
client=client,
predefined_acl=predefined_acl,
if_generation_match=if_generation_match,
Expand Down Expand Up @@ -3332,7 +3232,6 @@ def create_resumable_upload_session(
fake_stream,
content_type,
size,
None,
predefined_acl=predefined_acl,
if_generation_match=if_generation_match,
if_generation_not_match=if_generation_not_match,
Expand Down Expand Up @@ -4131,16 +4030,9 @@ def open(
For uploads only, the following additional arguments are supported:
- ``content_type``
- ``num_retries``
- ``predefined_acl``
- ``checksum``
.. note::
``num_retries`` is supported for backwards-compatibility
reasons only; please use ``retry`` with a Retry object or
ConditionalRetryPolicy instead.
:type mode: str
:param mode:
(Optional) A mode string, as per standard Python `open()` semantics.The first
Expand Down
Loading

0 comments on commit f77ba4e

Please sign in to comment.