Skip to content

Commit 58b5040

Browse files
committed
Fix: Remove deprecated num_retries argument (#1377)
1 parent 58c1d03 commit 58b5040

File tree

6 files changed

+14
-447
lines changed

6 files changed

+14
-447
lines changed

google/cloud/storage/_helpers.py

+3-20
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@
7272
("if_source_metageneration_not_match", "ifSourceMetagenerationNotMatch"),
7373
)
7474

75-
_NUM_RETRIES_MESSAGE = (
76-
"`num_retries` has been deprecated and will be removed in a future "
77-
"release. Use the `retry` argument with a Retry or ConditionalRetryPolicy "
78-
"object, or None, instead."
79-
)
80-
8175
# _NOW() returns the current local date and time.
8276
# It is preferred to use timezone-aware datetimes _NOW(_UTC),
8377
# which returns the current UTC date and time.
@@ -634,36 +628,25 @@ def _bucket_bound_hostname_url(host, scheme=None):
634628
return f"{scheme}://{host}"
635629

636630

637-
def _api_core_retry_to_resumable_media_retry(retry, num_retries=None):
631+
def _api_core_retry_to_resumable_media_retry(retry):
638632
"""Convert google.api.core.Retry to google.cloud.storage._media.RetryStrategy.
639633
640634
Custom predicates are not translated.
641635
642636
:type retry: google.api_core.Retry
643637
:param retry: (Optional) The google.api_core.Retry object to translate.
644638
645-
:type num_retries: int
646-
:param num_retries: (Optional) The number of retries desired. This is
647-
supported for backwards compatibility and is mutually exclusive with
648-
`retry`.
649-
650639
:rtype: google.cloud.storage._media.RetryStrategy
651-
:returns: A RetryStrategy with all applicable attributes copied from input,
652-
or a RetryStrategy with max_retries set to 0 if None was input.
640+
:returns: A RetryStrategy with all applicable attributes copied from input.
653641
"""
654642

655-
if retry is not None and num_retries is not None:
656-
raise ValueError("num_retries and retry arguments are mutually exclusive")
657-
658-
elif retry is not None:
643+
if retry is not None:
659644
return _media.RetryStrategy(
660645
max_sleep=retry._maximum,
661646
max_cumulative_retry=retry._deadline,
662647
initial_delay=retry._initial,
663648
multiplier=retry._multiplier,
664649
)
665-
elif num_retries is not None:
666-
return _media.RetryStrategy(max_retries=num_retries)
667650
else:
668651
return _media.RetryStrategy(max_retries=0)
669652

google/cloud/storage/blob.py

+2-110
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
from google.cloud.storage._helpers import _get_default_storage_base_url
6060
from google.cloud.storage._signing import generate_signed_url_v2
6161
from google.cloud.storage._signing import generate_signed_url_v4
62-
from google.cloud.storage._helpers import _NUM_RETRIES_MESSAGE
6362
from google.cloud.storage._helpers import _API_VERSION
6463
from google.cloud.storage._helpers import _virtual_hosted_style_base_url
6564
from google.cloud.storage._opentelemetry_tracing import create_trace_span
@@ -1863,7 +1862,6 @@ def _do_multipart_upload(
18631862
stream,
18641863
content_type,
18651864
size,
1866-
num_retries,
18671865
predefined_acl,
18681866
if_generation_match,
18691867
if_generation_not_match,
@@ -1900,15 +1898,6 @@ def _do_multipart_upload(
19001898
``stream``). If not provided, the upload will be concluded once
19011899
``stream`` is exhausted (or :data:`None`).
19021900
1903-
:type num_retries: int
1904-
:param num_retries:
1905-
Number of upload retries. By default, only uploads with
1906-
if_generation_match set will be retried, as uploads without the
1907-
argument are not guaranteed to be idempotent. Setting num_retries
1908-
will override this default behavior and guarantee retries even when
1909-
if_generation_match is not set. (Deprecated: This argument
1910-
will be removed in a future release.)
1911-
19121901
:type predefined_acl: str
19131902
:param predefined_acl: (Optional) Predefined access control list
19141903
@@ -2023,9 +2012,7 @@ def _do_multipart_upload(
20232012
upload_url = _add_query_parameters(base_url, name_value_pairs)
20242013
upload = MultipartUpload(upload_url, headers=headers, checksum=checksum)
20252014

2026-
upload._retry_strategy = _api_core_retry_to_resumable_media_retry(
2027-
retry, num_retries
2028-
)
2015+
upload._retry_strategy = _api_core_retry_to_resumable_media_retry(retry)
20292016

20302017
extra_attributes = {
20312018
"url.full": upload_url,
@@ -2050,7 +2037,6 @@ def _initiate_resumable_upload(
20502037
stream,
20512038
content_type,
20522039
size,
2053-
num_retries,
20542040
predefined_acl=None,
20552041
extra_headers=None,
20562042
chunk_size=None,
@@ -2092,15 +2078,6 @@ def _initiate_resumable_upload(
20922078
:type predefined_acl: str
20932079
:param predefined_acl: (Optional) Predefined access control list
20942080
2095-
:type num_retries: int
2096-
:param num_retries:
2097-
Number of upload retries. By default, only uploads with
2098-
if_generation_match set will be retried, as uploads without the
2099-
argument are not guaranteed to be idempotent. Setting num_retries
2100-
will override this default behavior and guarantee retries even when
2101-
if_generation_match is not set. (Deprecated: This argument
2102-
will be removed in a future release.)
2103-
21042081
:type extra_headers: dict
21052082
:param extra_headers:
21062083
(Optional) Extra headers to add to standard headers.
@@ -2230,9 +2207,7 @@ def _initiate_resumable_upload(
22302207
upload_url, chunk_size, headers=headers, checksum=checksum
22312208
)
22322209

2233-
upload._retry_strategy = _api_core_retry_to_resumable_media_retry(
2234-
retry, num_retries
2235-
)
2210+
upload._retry_strategy = _api_core_retry_to_resumable_media_retry(retry)
22362211

22372212
upload.initiate(
22382213
transport,
@@ -2252,7 +2227,6 @@ def _do_resumable_upload(
22522227
stream,
22532228
content_type,
22542229
size,
2255-
num_retries,
22562230
predefined_acl,
22572231
if_generation_match,
22582232
if_generation_not_match,
@@ -2292,15 +2266,6 @@ def _do_resumable_upload(
22922266
``stream``). If not provided, the upload will be concluded once
22932267
``stream`` is exhausted (or :data:`None`).
22942268
2295-
:type num_retries: int
2296-
:param num_retries:
2297-
Number of upload retries. By default, only uploads with
2298-
if_generation_match set will be retried, as uploads without the
2299-
argument are not guaranteed to be idempotent. Setting num_retries
2300-
will override this default behavior and guarantee retries even when
2301-
if_generation_match is not set. (Deprecated: This argument
2302-
will be removed in a future release.)
2303-
23042269
:type predefined_acl: str
23052270
:param predefined_acl: (Optional) Predefined access control list
23062271
@@ -2365,7 +2330,6 @@ def _do_resumable_upload(
23652330
stream,
23662331
content_type,
23672332
size,
2368-
num_retries,
23692333
predefined_acl=predefined_acl,
23702334
if_generation_match=if_generation_match,
23712335
if_generation_not_match=if_generation_not_match,
@@ -2403,7 +2367,6 @@ def _do_upload(
24032367
stream,
24042368
content_type,
24052369
size,
2406-
num_retries,
24072370
predefined_acl,
24082371
if_generation_match,
24092372
if_generation_not_match,
@@ -2444,15 +2407,6 @@ def _do_upload(
24442407
``stream``). If not provided, the upload will be concluded once
24452408
``stream`` is exhausted (or :data:`None`).
24462409
2447-
:type num_retries: int
2448-
:param num_retries:
2449-
Number of upload retries. By default, only uploads with
2450-
if_generation_match set will be retried, as uploads without the
2451-
argument are not guaranteed to be idempotent. Setting num_retries
2452-
will override this default behavior and guarantee retries even when
2453-
if_generation_match is not set. (Deprecated: This argument
2454-
will be removed in a future release.)
2455-
24562410
:type predefined_acl: str
24572411
:param predefined_acl: (Optional) Predefined access control list
24582412
@@ -2542,7 +2496,6 @@ def _do_upload(
25422496
stream,
25432497
content_type,
25442498
size,
2545-
num_retries,
25462499
predefined_acl,
25472500
if_generation_match,
25482501
if_generation_not_match,
@@ -2559,7 +2512,6 @@ def _do_upload(
25592512
stream,
25602513
content_type,
25612514
size,
2562-
num_retries,
25632515
predefined_acl,
25642516
if_generation_match,
25652517
if_generation_not_match,
@@ -2579,7 +2531,6 @@ def _prep_and_do_upload(
25792531
rewind=False,
25802532
size=None,
25812533
content_type=None,
2582-
num_retries=None,
25832534
client=None,
25842535
predefined_acl=None,
25852536
if_generation_match=None,
@@ -2637,15 +2588,6 @@ def _prep_and_do_upload(
26372588
:type content_type: str
26382589
:param content_type: (Optional) Type of content being uploaded.
26392590
2640-
:type num_retries: int
2641-
:param num_retries:
2642-
Number of upload retries. By default, only uploads with
2643-
if_generation_match set will be retried, as uploads without the
2644-
argument are not guaranteed to be idempotent. Setting num_retries
2645-
will override this default behavior and guarantee retries even when
2646-
if_generation_match is not set. (Deprecated: This argument
2647-
will be removed in a future release.)
2648-
26492591
:type client: :class:`~google.cloud.storage.client.Client`
26502592
:param client:
26512593
(Optional) The client to use. If not passed, falls back to the
@@ -2719,14 +2661,6 @@ def _prep_and_do_upload(
27192661
:raises: :class:`~google.cloud.exceptions.GoogleCloudError`
27202662
if the upload response returns an error status.
27212663
"""
2722-
if num_retries is not None:
2723-
warnings.warn(_NUM_RETRIES_MESSAGE, DeprecationWarning, stacklevel=2)
2724-
# num_retries and retry are mutually exclusive. If num_retries is
2725-
# set and retry is exactly the default, then nullify retry for
2726-
# backwards compatibility.
2727-
if retry is DEFAULT_RETRY_IF_GENERATION_SPECIFIED:
2728-
retry = None
2729-
27302664
_maybe_rewind(file_obj, rewind=rewind)
27312665
predefined_acl = ACL.validate_predefined(predefined_acl)
27322666

@@ -2736,7 +2670,6 @@ def _prep_and_do_upload(
27362670
file_obj,
27372671
content_type,
27382672
size,
2739-
num_retries,
27402673
predefined_acl,
27412674
if_generation_match,
27422675
if_generation_not_match,
@@ -2758,7 +2691,6 @@ def upload_from_file(
27582691
rewind=False,
27592692
size=None,
27602693
content_type=None,
2761-
num_retries=None,
27622694
client=None,
27632695
predefined_acl=None,
27642696
if_generation_match=None,
@@ -2815,15 +2747,6 @@ def upload_from_file(
28152747
:type content_type: str
28162748
:param content_type: (Optional) Type of content being uploaded.
28172749
2818-
:type num_retries: int
2819-
:param num_retries:
2820-
Number of upload retries. By default, only uploads with
2821-
if_generation_match set will be retried, as uploads without the
2822-
argument are not guaranteed to be idempotent. Setting num_retries
2823-
will override this default behavior and guarantee retries even when
2824-
if_generation_match is not set. (Deprecated: This argument
2825-
will be removed in a future release.)
2826-
28272750
:type client: :class:`~google.cloud.storage.client.Client`
28282751
:param client:
28292752
(Optional) The client to use. If not passed, falls back to the
@@ -2887,7 +2810,6 @@ def upload_from_file(
28872810
rewind=rewind,
28882811
size=size,
28892812
content_type=content_type,
2890-
num_retries=num_retries,
28912813
client=client,
28922814
predefined_acl=predefined_acl,
28932815
if_generation_match=if_generation_match,
@@ -2928,7 +2850,6 @@ def upload_from_filename(
29282850
self,
29292851
filename,
29302852
content_type=None,
2931-
num_retries=None,
29322853
client=None,
29332854
predefined_acl=None,
29342855
if_generation_match=None,
@@ -2977,15 +2898,6 @@ def upload_from_filename(
29772898
(Optional) The client to use. If not passed, falls back to the
29782899
``client`` stored on the blob's bucket.
29792900
2980-
:type num_retries: int
2981-
:param num_retries:
2982-
Number of upload retries. By default, only uploads with
2983-
if_generation_match set will be retried, as uploads without the
2984-
argument are not guaranteed to be idempotent. Setting num_retries
2985-
will override this default behavior and guarantee retries even when
2986-
if_generation_match is not set. (Deprecated: This argument
2987-
will be removed in a future release.)
2988-
29892901
:type predefined_acl: str
29902902
:param predefined_acl: (Optional) Predefined access control list
29912903
@@ -3040,7 +2952,6 @@ def upload_from_filename(
30402952
self._handle_filename_and_upload(
30412953
filename,
30422954
content_type=content_type,
3043-
num_retries=num_retries,
30442955
client=client,
30452956
predefined_acl=predefined_acl,
30462957
if_generation_match=if_generation_match,
@@ -3057,7 +2968,6 @@ def upload_from_string(
30572968
self,
30582969
data,
30592970
content_type="text/plain",
3060-
num_retries=None,
30612971
client=None,
30622972
predefined_acl=None,
30632973
if_generation_match=None,
@@ -3093,15 +3003,6 @@ def upload_from_string(
30933003
(Optional) Type of content being uploaded. Defaults to
30943004
``'text/plain'``.
30953005
3096-
:type num_retries: int
3097-
:param num_retries:
3098-
Number of upload retries. By default, only uploads with
3099-
if_generation_match set will be retried, as uploads without the
3100-
argument are not guaranteed to be idempotent. Setting num_retries
3101-
will override this default behavior and guarantee retries even when
3102-
if_generation_match is not set. (Deprecated: This argument
3103-
will be removed in a future release.)
3104-
31053006
:type client: :class:`~google.cloud.storage.client.Client`
31063007
:param client:
31073008
(Optional) The client to use. If not passed, falls back to the
@@ -3163,7 +3064,6 @@ def upload_from_string(
31633064
file_obj=string_buffer,
31643065
size=len(data),
31653066
content_type=content_type,
3166-
num_retries=num_retries,
31673067
client=client,
31683068
predefined_acl=predefined_acl,
31693069
if_generation_match=if_generation_match,
@@ -3332,7 +3232,6 @@ def create_resumable_upload_session(
33323232
fake_stream,
33333233
content_type,
33343234
size,
3335-
None,
33363235
predefined_acl=predefined_acl,
33373236
if_generation_match=if_generation_match,
33383237
if_generation_not_match=if_generation_not_match,
@@ -4131,16 +4030,9 @@ def open(
41314030
For uploads only, the following additional arguments are supported:
41324031
41334032
- ``content_type``
4134-
- ``num_retries``
41354033
- ``predefined_acl``
41364034
- ``checksum``
41374035
4138-
.. note::
4139-
4140-
``num_retries`` is supported for backwards-compatibility
4141-
reasons only; please use ``retry`` with a Retry object or
4142-
ConditionalRetryPolicy instead.
4143-
41444036
:type mode: str
41454037
:param mode:
41464038
(Optional) A mode string, as per standard Python `open()` semantics.The first

0 commit comments

Comments
 (0)