Skip to content

Commit 73bd270

Browse files
author
julien bonnier
committed
Update invocation metadata from grpc.aio.ServicerContext to use the correct syntax
1 parent fdbf22f commit 73bd270

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

src/a2a/server/request_handlers/grpc_handler.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,11 @@ def build(self, context: grpc.aio.ServicerContext) -> ServerCallContext:
5353
def _get_metadata_value(
5454
context: grpc.aio.ServicerContext, key: str
5555
) -> list[str]:
56-
md = context.invocation_metadata
56+
md = context.invocation_metadata()
5757
raw_values: list[str | bytes] = []
5858
if isinstance(md, Metadata):
5959
raw_values = md.get_all(key)
60-
elif isinstance(md, Sequence):
61-
lower_key = key.lower()
62-
raw_values = [e for (k, e) in md if k.lower() == lower_key]
60+
6361
return [e if isinstance(e, str) else e.decode('utf-8') for e in raw_values]
6462

6563

tests/server/request_handlers/test_grpc_handler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ async def test_send_message_with_extensions(
321321
mock_request_handler: AsyncMock,
322322
mock_grpc_context: AsyncMock,
323323
) -> None:
324-
mock_grpc_context.invocation_metadata = grpc.aio.Metadata(
324+
mock_grpc_context.invocation_metadata.return_value = grpc.aio.Metadata(
325325
(HTTP_EXTENSION_HEADER, 'foo'),
326326
(HTTP_EXTENSION_HEADER, 'bar'),
327327
)
@@ -361,7 +361,7 @@ async def test_send_message_with_comma_separated_extensions(
361361
mock_request_handler: AsyncMock,
362362
mock_grpc_context: AsyncMock,
363363
) -> None:
364-
mock_grpc_context.invocation_metadata = grpc.aio.Metadata(
364+
mock_grpc_context.invocation_metadata.return_value = grpc.aio.Metadata(
365365
(HTTP_EXTENSION_HEADER, 'foo ,, bar,'),
366366
(HTTP_EXTENSION_HEADER, 'baz , bar'),
367367
)
@@ -386,7 +386,7 @@ async def test_send_streaming_message_with_extensions(
386386
mock_request_handler: AsyncMock,
387387
mock_grpc_context: AsyncMock,
388388
) -> None:
389-
mock_grpc_context.invocation_metadata = grpc.aio.Metadata(
389+
mock_grpc_context.invocation_metadata.return_value = grpc.aio.Metadata(
390390
(HTTP_EXTENSION_HEADER, 'foo'),
391391
(HTTP_EXTENSION_HEADER, 'bar'),
392392
)

0 commit comments

Comments
 (0)