Skip to content

Commit 3bd2493

Browse files
authored
Merge pull request #3164 from dhermes/remove-dead-ds-code
Removing unused code-path for remapping raw gRPC exceptions in datastore.
2 parents 4482c75 + 930fb6f commit 3bd2493

File tree

2 files changed

+18
-56
lines changed

2 files changed

+18
-56
lines changed

datastore/google/cloud/datastore/_gax.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060

6161

6262
@contextlib.contextmanager
63-
def _grpc_catch_rendezvous():
64-
"""Remap gRPC exceptions that happen in context.
63+
def _catch_remap_gax_error():
64+
"""Remap GAX exceptions that happen in context.
6565
6666
.. _code.proto: https://github.com/googleapis/googleapis/blob/\
6767
master/google/rpc/code.proto
@@ -80,14 +80,6 @@ def _grpc_catch_rendezvous():
8080
else:
8181
new_exc = error_class(exc.cause.details())
8282
six.reraise(error_class, new_exc, sys.exc_info()[2])
83-
except exceptions.GrpcRendezvous as exc:
84-
error_code = exc.code()
85-
error_class = _GRPC_ERROR_MAPPING.get(error_code)
86-
if error_class is None:
87-
raise
88-
else:
89-
new_exc = error_class(exc.details())
90-
six.reraise(error_class, new_exc, sys.exc_info()[2])
9183

9284

9385
class GAPICDatastoreAPI(datastore_client.DatastoreClient):
@@ -119,7 +111,7 @@ def lookup(self, *args, **kwargs):
119111
:rtype: :class:`.datastore_pb2.LookupResponse`
120112
:returns: The returned protobuf response object.
121113
"""
122-
with _grpc_catch_rendezvous():
114+
with _catch_remap_gax_error():
123115
return super(GAPICDatastoreAPI, self).lookup(*args, **kwargs)
124116

125117
def run_query(self, *args, **kwargs):
@@ -138,7 +130,7 @@ def run_query(self, *args, **kwargs):
138130
:rtype: :class:`.datastore_pb2.RunQueryResponse`
139131
:returns: The returned protobuf response object.
140132
"""
141-
with _grpc_catch_rendezvous():
133+
with _catch_remap_gax_error():
142134
return super(GAPICDatastoreAPI, self).run_query(*args, **kwargs)
143135

144136
def begin_transaction(self, *args, **kwargs):
@@ -157,7 +149,7 @@ def begin_transaction(self, *args, **kwargs):
157149
:rtype: :class:`.datastore_pb2.BeginTransactionResponse`
158150
:returns: The returned protobuf response object.
159151
"""
160-
with _grpc_catch_rendezvous():
152+
with _catch_remap_gax_error():
161153
return super(GAPICDatastoreAPI, self).begin_transaction(
162154
*args, **kwargs)
163155

@@ -177,7 +169,7 @@ def commit(self, *args, **kwargs):
177169
:rtype: :class:`.datastore_pb2.CommitResponse`
178170
:returns: The returned protobuf response object.
179171
"""
180-
with _grpc_catch_rendezvous():
172+
with _catch_remap_gax_error():
181173
return super(GAPICDatastoreAPI, self).commit(*args, **kwargs)
182174

183175
def rollback(self, *args, **kwargs):
@@ -196,7 +188,7 @@ def rollback(self, *args, **kwargs):
196188
:rtype: :class:`.datastore_pb2.RollbackResponse`
197189
:returns: The returned protobuf response object.
198190
"""
199-
with _grpc_catch_rendezvous():
191+
with _catch_remap_gax_error():
200192
return super(GAPICDatastoreAPI, self).rollback(*args, **kwargs)
201193

202194
def allocate_ids(self, *args, **kwargs):
@@ -215,7 +207,7 @@ def allocate_ids(self, *args, **kwargs):
215207
:rtype: :class:`.datastore_pb2.AllocateIdsResponse`
216208
:returns: The returned protobuf response object.
217209
"""
218-
with _grpc_catch_rendezvous():
210+
with _catch_remap_gax_error():
219211
return super(GAPICDatastoreAPI, self).allocate_ids(
220212
*args, **kwargs)
221213

datastore/unit_tests/test__gax.py

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121

2222
@unittest.skipUnless(_HAVE_GRPC, 'No gRPC')
23-
class Test__grpc_catch_rendezvous(unittest.TestCase):
23+
class Test__catch_remap_gax_error(unittest.TestCase):
2424

2525
def _call_fut(self):
26-
from google.cloud.datastore._gax import _grpc_catch_rendezvous
26+
from google.cloud.datastore._gax import _catch_remap_gax_error
2727

28-
return _grpc_catch_rendezvous()
28+
return _catch_remap_gax_error()
2929

3030
@staticmethod
3131
def _fake_method(exc, result=None):
@@ -48,37 +48,7 @@ def test_success(self):
4848
result = self._fake_method(None, expected)
4949
self.assertIs(result, expected)
5050

51-
def test_failure_aborted(self):
52-
from grpc import StatusCode
53-
from google.cloud.exceptions import Conflict
54-
55-
details = 'Bad things.'
56-
exc = self._make_rendezvous(StatusCode.ABORTED, details)
57-
with self.assertRaises(Conflict):
58-
with self._call_fut():
59-
self._fake_method(exc)
60-
61-
def test_failure_invalid_argument(self):
62-
from grpc import StatusCode
63-
from google.cloud.exceptions import BadRequest
64-
65-
details = ('Cannot have inequality filters on multiple '
66-
'properties: [created, priority]')
67-
exc = self._make_rendezvous(StatusCode.INVALID_ARGUMENT, details)
68-
with self.assertRaises(BadRequest):
69-
with self._call_fut():
70-
self._fake_method(exc)
71-
72-
def test_failure_cancelled(self):
73-
from google.cloud.exceptions import GrpcRendezvous
74-
from grpc import StatusCode
75-
76-
exc = self._make_rendezvous(StatusCode.CANCELLED, None)
77-
with self.assertRaises(GrpcRendezvous):
78-
with self._call_fut():
79-
self._fake_method(exc)
80-
81-
def test_commit_failure_non_grpc_err(self):
51+
def test_non_grpc_err(self):
8252
exc = RuntimeError('Not a gRPC error')
8353
with self.assertRaises(RuntimeError):
8454
with self._call_fut():
@@ -132,7 +102,7 @@ def test_lookup(self):
132102
return_value=None)
133103
patch2 = mock.patch.object(datastore_client.DatastoreClient, 'lookup')
134104
patch3 = mock.patch(
135-
'google.cloud.datastore._gax._grpc_catch_rendezvous')
105+
'google.cloud.datastore._gax._catch_remap_gax_error')
136106

137107
with patch1 as mock_constructor:
138108
ds_api = self._make_one()
@@ -153,7 +123,7 @@ def test_run_query(self):
153123
patch2 = mock.patch.object(
154124
datastore_client.DatastoreClient, 'run_query')
155125
patch3 = mock.patch(
156-
'google.cloud.datastore._gax._grpc_catch_rendezvous')
126+
'google.cloud.datastore._gax._catch_remap_gax_error')
157127

158128
with patch1 as mock_constructor:
159129
ds_api = self._make_one()
@@ -174,7 +144,7 @@ def test_begin_transaction(self):
174144
patch2 = mock.patch.object(
175145
datastore_client.DatastoreClient, 'begin_transaction')
176146
patch3 = mock.patch(
177-
'google.cloud.datastore._gax._grpc_catch_rendezvous')
147+
'google.cloud.datastore._gax._catch_remap_gax_error')
178148

179149
with patch1 as mock_constructor:
180150
ds_api = self._make_one()
@@ -195,7 +165,7 @@ def test_commit(self):
195165
return_value=None)
196166
patch2 = mock.patch.object(datastore_client.DatastoreClient, 'commit')
197167
patch3 = mock.patch(
198-
'google.cloud.datastore._gax._grpc_catch_rendezvous')
168+
'google.cloud.datastore._gax._catch_remap_gax_error')
199169

200170
with patch1 as mock_constructor:
201171
ds_api = self._make_one()
@@ -216,7 +186,7 @@ def test_rollback(self):
216186
patch2 = mock.patch.object(
217187
datastore_client.DatastoreClient, 'rollback')
218188
patch3 = mock.patch(
219-
'google.cloud.datastore._gax._grpc_catch_rendezvous')
189+
'google.cloud.datastore._gax._catch_remap_gax_error')
220190

221191
with patch1 as mock_constructor:
222192
ds_api = self._make_one()
@@ -237,7 +207,7 @@ def test_allocate_ids(self):
237207
patch2 = mock.patch.object(
238208
datastore_client.DatastoreClient, 'allocate_ids')
239209
patch3 = mock.patch(
240-
'google.cloud.datastore._gax._grpc_catch_rendezvous')
210+
'google.cloud.datastore._gax._catch_remap_gax_error')
241211

242212
with patch1 as mock_constructor:
243213
ds_api = self._make_one()

0 commit comments

Comments
 (0)