Skip to content

Commit 523100f

Browse files
committed
Upgrading google-gax to 0.14.1.
In the process, adding back code changes that were reverted in the process of reverting PR googleapis#2336. Some of the changes were necessary, but anything using GAX (logging and pubsub) could safely be restored.
1 parent f2ba165 commit 523100f

File tree

15 files changed

+42
-82
lines changed

15 files changed

+42
-82
lines changed

google/cloud/_helpers.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,9 @@
3131
except ImportError:
3232
app_identity = None
3333
try:
34-
from google.gax.grpc import exc_to_code as beta_exc_to_code
3534
import grpc
36-
from grpc._channel import _Rendezvous
3735
except ImportError: # pragma: NO COVER
38-
beta_exc_to_code = None
3936
grpc = None
40-
_Rendezvous = Exception
4137
import six
4238
from six.moves import http_client
4339
from six.moves import configparser
@@ -685,21 +681,6 @@ def make_insecure_stub(stub_class, host, port=None):
685681
return stub_class(channel)
686682

687683

688-
def exc_to_code(exc):
689-
"""Retrieves the status code from a gRPC exception.
690-
691-
:type exc: :class:`Exception`
692-
:param exc: An exception from gRPC beta or stable.
693-
694-
:rtype: :class:`grpc.StatusCode`
695-
:returns: The status code attached to the exception.
696-
"""
697-
if isinstance(exc, _Rendezvous):
698-
return exc.code()
699-
else:
700-
return beta_exc_to_code(exc)
701-
702-
703684
try:
704685
from pytz import UTC # pylint: disable=unused-import,wrong-import-order
705686
except ImportError:

google/cloud/bigtable/row_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class InvalidChunk(RuntimeError):
183183
class PartialRowsData(object):
184184
"""Convenience wrapper for consuming a ``ReadRows`` streaming response.
185185
186-
:type response_iterator: :class:`grpc._channel._Rendezvous`
186+
:type response_iterator: :class:`~google.cloud.exceptions.GrpcRendezvous`
187187
:param response_iterator: A streaming iterator returned from a
188188
``ReadRows`` request.
189189
"""

google/cloud/bigtable/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def sample_row_keys(self):
302302
samples would require space roughly equal to the difference in their
303303
``offset_bytes`` fields.
304304
305-
:rtype: :class:`grpc._channel._Rendezvous`
305+
:rtype: :class:`~google.cloud.exceptions.GrpcRendezvous`
306306
:returns: A cancel-able iterator. Can be consumed by calling ``next()``
307307
or by casting to a :class:`list` and can be cancelled by
308308
calling ``cancel()``.

google/cloud/datastore/connection.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,17 @@
2424
from google.cloud.environment_vars import DISABLE_GRPC
2525
from google.cloud.environment_vars import GCD_HOST
2626
from google.cloud.exceptions import Conflict
27+
from google.cloud.exceptions import GrpcRendezvous
2728
from google.cloud.exceptions import make_exception
2829
from google.cloud.datastore._generated import datastore_pb2 as _datastore_pb2
2930
# pylint: disable=ungrouped-imports
3031
try:
3132
from grpc import StatusCode
32-
from grpc._channel import _Rendezvous
3333
from google.cloud.datastore._generated import datastore_grpc_pb2
3434
except ImportError: # pragma: NO COVER
3535
_HAVE_GRPC = False
3636
datastore_grpc_pb2 = None
3737
StatusCode = None
38-
_Rendezvous = Exception
3938
else:
4039
_HAVE_GRPC = True
4140
# pylint: enable=ungrouped-imports
@@ -313,7 +312,7 @@ def commit(self, project, request_pb):
313312
request_pb.project_id = project
314313
try:
315314
return self._stub.Commit(request_pb)
316-
except _Rendezvous as exc:
315+
except GrpcRendezvous as exc:
317316
if exc.code() == StatusCode.ABORTED:
318317
raise Conflict(exc.details())
319318
raise

google/cloud/exceptions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@
2525

2626
_HTTP_CODE_TO_EXCEPTION = {} # populated at end of module
2727

28+
try:
29+
from grpc._channel import _Rendezvous
30+
except ImportError: # pragma: NO COVER
31+
_Rendezvous = None
32+
33+
34+
# pylint: disable=invalid-name
35+
GrpcRendezvous = _Rendezvous
36+
"""Exception class raised by gRPC stable."""
37+
# pylint: enable=invalid-name
38+
2839

2940
class GoogleCloudError(Exception):
3041
"""Base error class for Google Cloud errors (abstract).

google/cloud/logging/_gax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from google.gax import CallOptions
2020
from google.gax import INITIAL_PAGE
2121
from google.gax.errors import GaxError
22+
from google.gax.grpc import exc_to_code
2223
from google.logging.type.log_severity_pb2 import LogSeverity
2324
from google.logging.v2.logging_config_pb2 import LogSink
2425
from google.logging.v2.logging_metrics_pb2 import LogMetric
@@ -29,7 +30,6 @@
2930
# pylint: disable=ungrouped-imports
3031
from google.cloud._helpers import _datetime_to_pb_timestamp
3132
from google.cloud._helpers import _pb_timestamp_to_rfc3339
32-
from google.cloud._helpers import exc_to_code
3333
from google.cloud.exceptions import Conflict
3434
from google.cloud.exceptions import NotFound
3535
# pylint: enable=ungrouped-imports

google/cloud/pubsub/_gax.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
from google.gax import CallOptions
2020
from google.gax import INITIAL_PAGE
2121
from google.gax.errors import GaxError
22+
from google.gax.grpc import exc_to_code
2223
from google.pubsub.v1.pubsub_pb2 import PubsubMessage
2324
from google.pubsub.v1.pubsub_pb2 import PushConfig
24-
from grpc.beta.implementations import insecure_channel
25+
from grpc import insecure_channel
2526
from grpc import StatusCode
2627

2728
# pylint: disable=ungrouped-imports
2829
from google.cloud._helpers import _to_bytes
29-
from google.cloud._helpers import exc_to_code
3030
from google.cloud._helpers import _pb_timestamp_to_rfc3339
3131
from google.cloud.exceptions import Conflict
3232
from google.cloud.exceptions import NotFound
@@ -520,7 +520,7 @@ def make_gax_publisher_api(connection):
520520
"""
521521
channel = None
522522
if connection.in_emulator:
523-
channel = insecure_channel(connection.host, None)
523+
channel = insecure_channel(connection.host)
524524
return PublisherApi(channel=channel)
525525

526526

@@ -540,5 +540,5 @@ def make_gax_subscriber_api(connection):
540540
"""
541541
channel = None
542542
if connection.in_emulator:
543-
channel = insecure_channel(connection.host, None)
543+
channel = insecure_channel(connection.host)
544544
return SubscriberApi(channel=channel)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
GRPC_PACKAGES = [
2323
'grpcio >= 1.0.0',
24-
'google-gax >= 0.13.0, < 0.14dev',
24+
'google-gax >= 0.14.1, < 0.15dev',
2525
'gapic-google-pubsub-v1 >= 0.9.0, < 0.10dev',
2626
'grpc-google-pubsub-v1 >= 0.9.0, < 0.10dev',
2727
'gapic-google-logging-v2 >= 0.9.0, < 0.10dev',

system_tests/bigtable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _retry_on_unavailable(exc):
9393

9494

9595
def setUpModule():
96-
from grpc._channel import _Rendezvous
96+
from google.cloud.exceptions import GrpcRendezvous
9797

9898
Config.IN_EMULATOR = os.getenv(BIGTABLE_EMULATOR) is not None
9999

@@ -106,7 +106,7 @@ def setUpModule():
106106
Config.INSTANCE = Config.CLIENT.instance(INSTANCE_ID, LOCATION_ID)
107107

108108
if not Config.IN_EMULATOR:
109-
retry = RetryErrors(_Rendezvous,
109+
retry = RetryErrors(GrpcRendezvous,
110110
error_predicate=_retry_on_unavailable)
111111
instances, failed_locations = retry(Config.CLIENT.list_instances)()
112112

system_tests/logging_.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ def _logger_name():
7373
return 'system-tests-logger' + unique_resource_id('-')
7474

7575
def _list_entries(self, logger):
76-
from grpc._channel import _Rendezvous
76+
from google.gax.errors import GaxError
77+
7778
inner = RetryResult(_has_entries)(logger.list_entries)
78-
outer = RetryErrors(_Rendezvous, _retry_on_unavailable)(inner)
79+
outer = RetryErrors(GaxError, _retry_on_unavailable)(inner)
7980
return outer()
8081

8182
def test_log_text(self):

0 commit comments

Comments
 (0)