Skip to content

Commit 4fe6a57

Browse files
committed
cater for breaking change in gRPC 1.75.0
1 parent c389948 commit 4fe6a57

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tests/system/conftest.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
except:
6262
HAS_ASYNC_REST_IDENTITY_TRANSPORT = False
6363

64+
_GRPC_VERSION = grpc.__version__
65+
6466
# TODO: use async auth anon credentials by default once the minimum version of google-auth is upgraded.
6567
# See related issue: https://github.com/googleapis/gapic-generator-python/issues/2107.
6668
def async_anonymous_credentials():
@@ -366,11 +368,20 @@ def __init__(self, key, value):
366368

367369
async def _add_request_metadata(self, client_call_details):
368370
if client_call_details.metadata is not None:
371+
# As of gRPC 1.75.0 and newer,
369372
# https://grpc.github.io/grpc/python/grpc_asyncio.html#grpc.aio.Metadata
370373
# Note that for async, `ClientCallDetails.metadata` is a mapping.
371374
# Whereas for sync, `ClientCallDetails.metadata` is a list.
372375
# https://grpc.github.io/grpc/python/glossary.html#term-metadata.
373-
client_call_details.metadata[self._key] = self._value
376+
# Prior to gRPC 1.75.0, `ClientCallDetails.metadata` is a list
377+
# for both sync and async.
378+
grpc_major, grpc_minor = [
379+
int(part) for part in _GRPC_VERSION.split(".")[0:2]
380+
]
381+
if grpc_major == 1 and grpc_minor < 75:
382+
client_call_details.metadata.append((self._key, self._value))
383+
else:
384+
client_call_details.metadata[self._key] = self._value
374385
self.request_metadata = list(client_call_details.metadata)
375386

376387
async def intercept_unary_unary(self, continuation, client_call_details, request):

0 commit comments

Comments
 (0)