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

Fix: Remove deprecated num_retries argument #1377

Merged
merged 1 commit into from
Nov 12, 2024
Merged
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
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 @@ -631,36 +625,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.acl import ACL
Expand Down Expand Up @@ -1829,7 +1828,6 @@ def _do_multipart_upload(
stream,
content_type,
size,
num_retries,
predefined_acl,
if_generation_match,
if_generation_not_match,
Expand Down Expand Up @@ -1866,15 +1864,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 @@ -1989,9 +1978,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)

response = upload.transmit(
transport, data, object_metadata, content_type, timeout=timeout
Expand All @@ -2005,7 +1992,6 @@ def _initiate_resumable_upload(
stream,
content_type,
size,
num_retries,
predefined_acl=None,
extra_headers=None,
chunk_size=None,
Expand Down Expand Up @@ -2047,15 +2033,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 @@ -2185,9 +2162,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 @@ -2207,7 +2182,6 @@ def _do_resumable_upload(
stream,
content_type,
size,
num_retries,
predefined_acl,
if_generation_match,
if_generation_not_match,
Expand Down Expand Up @@ -2247,15 +2221,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 @@ -2320,7 +2285,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 All @@ -2346,7 +2310,6 @@ def _do_upload(
stream,
content_type,
size,
num_retries,
predefined_acl,
if_generation_match,
if_generation_not_match,
Expand Down Expand Up @@ -2387,15 +2350,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 @@ -2485,7 +2439,6 @@ def _do_upload(
stream,
content_type,
size,
num_retries,
predefined_acl,
if_generation_match,
if_generation_not_match,
Expand All @@ -2502,7 +2455,6 @@ def _do_upload(
stream,
content_type,
size,
num_retries,
predefined_acl,
if_generation_match,
if_generation_not_match,
Expand All @@ -2522,7 +2474,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 @@ -2580,15 +2531,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 @@ -2662,14 +2604,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 @@ -2679,7 +2613,6 @@ def _prep_and_do_upload(
file_obj,
content_type,
size,
num_retries,
predefined_acl,
if_generation_match,
if_generation_not_match,
Expand All @@ -2700,7 +2633,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 @@ -2757,15 +2689,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 @@ -2829,7 +2752,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 @@ -2869,7 +2791,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 @@ -2918,15 +2839,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 @@ -2981,7 +2893,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 @@ -2997,7 +2908,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 @@ -3033,15 +2943,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 @@ -3103,7 +3004,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 @@ -3271,7 +3171,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 @@ -4061,16 +3960,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