Skip to content

Commit cd53350

Browse files
fix: use correct retry deadline (#121)
fix: require proto-plus>=1.15.0
1 parent 22fad60 commit cd53350

8 files changed

Lines changed: 114 additions & 148 deletions

File tree

packages/google-cloud-bigquery-datatransfer/UPGRADING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--
1+
<!--
22
Copyright 2020 Google LLC
33
44
Licensed under the Apache License, Version 2.0 (the "License");
@@ -80,7 +80,7 @@ that will convert most common use cases.
8080
* Install the library
8181

8282
```py
83-
python3 -m pip install google-cloud-bigquery-datatransfer
83+
python3 -m pip install google-cloud-bigquery-datatransfer[libcst]
8484
```
8585

8686
* The script `fixup_datatransfer_v1_keywords.py` is shipped with the library. It expects

packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/async_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ async def get_data_source(
256256
predicate=retries.if_exception_type(
257257
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
258258
),
259+
deadline=20.0,
259260
),
260261
default_timeout=20.0,
261262
client_info=DEFAULT_CLIENT_INFO,
@@ -343,6 +344,7 @@ async def list_data_sources(
343344
predicate=retries.if_exception_type(
344345
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
345346
),
347+
deadline=20.0,
346348
),
347349
default_timeout=20.0,
348350
client_info=DEFAULT_CLIENT_INFO,
@@ -621,6 +623,7 @@ async def delete_transfer_config(
621623
predicate=retries.if_exception_type(
622624
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
623625
),
626+
deadline=20.0,
624627
),
625628
default_timeout=20.0,
626629
client_info=DEFAULT_CLIENT_INFO,
@@ -709,6 +712,7 @@ async def get_transfer_config(
709712
predicate=retries.if_exception_type(
710713
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
711714
),
715+
deadline=20.0,
712716
),
713717
default_timeout=20.0,
714718
client_info=DEFAULT_CLIENT_INFO,
@@ -795,6 +799,7 @@ async def list_transfer_configs(
795799
predicate=retries.if_exception_type(
796800
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
797801
),
802+
deadline=20.0,
798803
),
799804
default_timeout=20.0,
800805
client_info=DEFAULT_CLIENT_INFO,
@@ -1036,6 +1041,7 @@ async def get_transfer_run(
10361041
predicate=retries.if_exception_type(
10371042
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
10381043
),
1044+
deadline=20.0,
10391045
),
10401046
default_timeout=20.0,
10411047
client_info=DEFAULT_CLIENT_INFO,
@@ -1114,6 +1120,7 @@ async def delete_transfer_run(
11141120
predicate=retries.if_exception_type(
11151121
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
11161122
),
1123+
deadline=20.0,
11171124
),
11181125
default_timeout=20.0,
11191126
client_info=DEFAULT_CLIENT_INFO,
@@ -1202,6 +1209,7 @@ async def list_transfer_runs(
12021209
predicate=retries.if_exception_type(
12031210
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
12041211
),
1212+
deadline=20.0,
12051213
),
12061214
default_timeout=20.0,
12071215
client_info=DEFAULT_CLIENT_INFO,
@@ -1295,6 +1303,7 @@ async def list_transfer_logs(
12951303
predicate=retries.if_exception_type(
12961304
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
12971305
),
1306+
deadline=20.0,
12981307
),
12991308
default_timeout=20.0,
13001309
client_info=DEFAULT_CLIENT_INFO,
@@ -1396,6 +1405,7 @@ async def check_valid_creds(
13961405
predicate=retries.if_exception_type(
13971406
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
13981407
),
1408+
deadline=20.0,
13991409
),
14001410
default_timeout=20.0,
14011411
client_info=DEFAULT_CLIENT_INFO,

packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/base.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,20 @@ def __init__(
7171
scope (Optional[Sequence[str]]): A list of scopes.
7272
quota_project_id (Optional[str]): An optional project to use for billing
7373
and quota.
74-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
75-
The client info used to send a user-agent string along with
76-
API requests. If ``None``, then default info will be used.
77-
Generally, you only need to set this if you're developing
74+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
75+
The client info used to send a user-agent string along with
76+
API requests. If ``None``, then default info will be used.
77+
Generally, you only need to set this if you're developing
7878
your own client library.
7979
"""
8080
# Save the hostname. Default to port 443 (HTTPS) if none is specified.
8181
if ":" not in host:
8282
host += ":443"
8383
self._host = host
8484

85+
# Save the scopes.
86+
self._scopes = scopes or self.AUTH_SCOPES
87+
8588
# If no credentials are provided, then determine the appropriate
8689
# defaults.
8790
if credentials and credentials_file:
@@ -91,20 +94,17 @@ def __init__(
9194

9295
if credentials_file is not None:
9396
credentials, _ = auth.load_credentials_from_file(
94-
credentials_file, scopes=scopes, quota_project_id=quota_project_id
97+
credentials_file, scopes=self._scopes, quota_project_id=quota_project_id
9598
)
9699

97100
elif credentials is None:
98101
credentials, _ = auth.default(
99-
scopes=scopes, quota_project_id=quota_project_id
102+
scopes=self._scopes, quota_project_id=quota_project_id
100103
)
101104

102105
# Save the credentials.
103106
self._credentials = credentials
104107

105-
# Lifted into its own function so it can be stubbed out during tests.
106-
self._prep_wrapped_messages(client_info)
107-
108108
def _prep_wrapped_messages(self, client_info):
109109
# Precompute the wrapped methods.
110110
self._wrapped_methods = {
@@ -117,6 +117,7 @@ def _prep_wrapped_messages(self, client_info):
117117
predicate=retries.if_exception_type(
118118
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
119119
),
120+
deadline=20.0,
120121
),
121122
default_timeout=20.0,
122123
client_info=client_info,
@@ -130,6 +131,7 @@ def _prep_wrapped_messages(self, client_info):
130131
predicate=retries.if_exception_type(
131132
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
132133
),
134+
deadline=20.0,
133135
),
134136
default_timeout=20.0,
135137
client_info=client_info,
@@ -153,6 +155,7 @@ def _prep_wrapped_messages(self, client_info):
153155
predicate=retries.if_exception_type(
154156
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
155157
),
158+
deadline=20.0,
156159
),
157160
default_timeout=20.0,
158161
client_info=client_info,
@@ -166,6 +169,7 @@ def _prep_wrapped_messages(self, client_info):
166169
predicate=retries.if_exception_type(
167170
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
168171
),
172+
deadline=20.0,
169173
),
170174
default_timeout=20.0,
171175
client_info=client_info,
@@ -179,6 +183,7 @@ def _prep_wrapped_messages(self, client_info):
179183
predicate=retries.if_exception_type(
180184
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
181185
),
186+
deadline=20.0,
182187
),
183188
default_timeout=20.0,
184189
client_info=client_info,
@@ -202,6 +207,7 @@ def _prep_wrapped_messages(self, client_info):
202207
predicate=retries.if_exception_type(
203208
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
204209
),
210+
deadline=20.0,
205211
),
206212
default_timeout=20.0,
207213
client_info=client_info,
@@ -215,6 +221,7 @@ def _prep_wrapped_messages(self, client_info):
215221
predicate=retries.if_exception_type(
216222
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
217223
),
224+
deadline=20.0,
218225
),
219226
default_timeout=20.0,
220227
client_info=client_info,
@@ -228,6 +235,7 @@ def _prep_wrapped_messages(self, client_info):
228235
predicate=retries.if_exception_type(
229236
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
230237
),
238+
deadline=20.0,
231239
),
232240
default_timeout=20.0,
233241
client_info=client_info,
@@ -241,6 +249,7 @@ def _prep_wrapped_messages(self, client_info):
241249
predicate=retries.if_exception_type(
242250
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
243251
),
252+
deadline=20.0,
244253
),
245254
default_timeout=20.0,
246255
client_info=client_info,
@@ -254,6 +263,7 @@ def _prep_wrapped_messages(self, client_info):
254263
predicate=retries.if_exception_type(
255264
exceptions.DeadlineExceeded, exceptions.ServiceUnavailable,
256265
),
266+
deadline=20.0,
257267
),
258268
default_timeout=20.0,
259269
client_info=client_info,

packages/google-cloud-bigquery-datatransfer/google/cloud/bigquery_datatransfer_v1/services/data_transfer_service/transports/grpc.py

Lines changed: 37 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -111,96 +111,69 @@ def __init__(
111111
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
112112
and ``credentials_file`` are passed.
113113
"""
114+
self._grpc_channel = None
114115
self._ssl_channel_credentials = ssl_channel_credentials
116+
self._stubs: Dict[str, Callable] = {}
115117

116118
if api_mtls_endpoint:
117119
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
118120
if client_cert_source:
119121
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
120122

121123
if channel:
122-
# Sanity check: Ensure that channel and credentials are not both
123-
# provided.
124+
# Ignore credentials if a channel was passed.
124125
credentials = False
125-
126126
# If a channel was explicitly provided, set it.
127127
self._grpc_channel = channel
128128
self._ssl_channel_credentials = None
129-
elif api_mtls_endpoint:
130-
host = (
131-
api_mtls_endpoint
132-
if ":" in api_mtls_endpoint
133-
else api_mtls_endpoint + ":443"
134-
)
135-
136-
if credentials is None:
137-
credentials, _ = auth.default(
138-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
139-
)
140-
141-
# Create SSL credentials with client_cert_source or application
142-
# default SSL credentials.
143-
if client_cert_source:
144-
cert, key = client_cert_source()
145-
ssl_credentials = grpc.ssl_channel_credentials(
146-
certificate_chain=cert, private_key=key
147-
)
148-
else:
149-
ssl_credentials = SslCredentials().ssl_credentials
150129

151-
# create a new channel. The provided one is ignored.
152-
self._grpc_channel = type(self).create_channel(
153-
host,
154-
credentials=credentials,
155-
credentials_file=credentials_file,
156-
ssl_credentials=ssl_credentials,
157-
scopes=scopes or self.AUTH_SCOPES,
158-
quota_project_id=quota_project_id,
159-
options=[
160-
("grpc.max_send_message_length", -1),
161-
("grpc.max_receive_message_length", -1),
162-
],
163-
)
164-
self._ssl_channel_credentials = ssl_credentials
165130
else:
166-
host = host if ":" in host else host + ":443"
131+
if api_mtls_endpoint:
132+
host = api_mtls_endpoint
133+
134+
# Create SSL credentials with client_cert_source or application
135+
# default SSL credentials.
136+
if client_cert_source:
137+
cert, key = client_cert_source()
138+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
139+
certificate_chain=cert, private_key=key
140+
)
141+
else:
142+
self._ssl_channel_credentials = SslCredentials().ssl_credentials
167143

168-
if credentials is None:
169-
credentials, _ = auth.default(
170-
scopes=self.AUTH_SCOPES, quota_project_id=quota_project_id
171-
)
144+
else:
145+
if client_cert_source_for_mtls and not ssl_channel_credentials:
146+
cert, key = client_cert_source_for_mtls()
147+
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
148+
certificate_chain=cert, private_key=key
149+
)
172150

173-
if client_cert_source_for_mtls and not ssl_channel_credentials:
174-
cert, key = client_cert_source_for_mtls()
175-
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
176-
certificate_chain=cert, private_key=key
177-
)
151+
# The base transport sets the host, credentials and scopes
152+
super().__init__(
153+
host=host,
154+
credentials=credentials,
155+
credentials_file=credentials_file,
156+
scopes=scopes,
157+
quota_project_id=quota_project_id,
158+
client_info=client_info,
159+
)
178160

179-
# create a new channel. The provided one is ignored.
161+
if not self._grpc_channel:
180162
self._grpc_channel = type(self).create_channel(
181-
host,
182-
credentials=credentials,
163+
self._host,
164+
credentials=self._credentials,
183165
credentials_file=credentials_file,
166+
scopes=self._scopes,
184167
ssl_credentials=self._ssl_channel_credentials,
185-
scopes=scopes or self.AUTH_SCOPES,
186168
quota_project_id=quota_project_id,
187169
options=[
188170
("grpc.max_send_message_length", -1),
189171
("grpc.max_receive_message_length", -1),
190172
],
191173
)
192174

193-
self._stubs = {} # type: Dict[str, Callable]
194-
195-
# Run the base constructor.
196-
super().__init__(
197-
host=host,
198-
credentials=credentials,
199-
credentials_file=credentials_file,
200-
scopes=scopes or self.AUTH_SCOPES,
201-
quota_project_id=quota_project_id,
202-
client_info=client_info,
203-
)
175+
# Wrap messages. This must be done after self._grpc_channel exists
176+
self._prep_wrapped_messages(client_info)
204177

205178
@classmethod
206179
def create_channel(
@@ -214,7 +187,7 @@ def create_channel(
214187
) -> grpc.Channel:
215188
"""Create and return a gRPC channel object.
216189
Args:
217-
address (Optional[str]): The host for the channel to use.
190+
host (Optional[str]): The host for the channel to use.
218191
credentials (Optional[~.Credentials]): The
219192
authorization credentials to attach to requests. These
220193
credentials identify this application to the service. If

0 commit comments

Comments
 (0)