Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/a2a/server/request_handlers/grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging

from abc import ABC, abstractmethod
from collections.abc import AsyncIterable, Sequence

Check failure on line 6 in src/a2a/server/request_handlers/grpc_handler.py

View workflow job for this annotation

GitHub Actions / Lint Code Base

Ruff (F401)

src/a2a/server/request_handlers/grpc_handler.py:6:44: F401 `collections.abc.Sequence` imported but unused


try:
Expand Down Expand Up @@ -53,13 +53,11 @@
def _get_metadata_value(
context: grpc.aio.ServicerContext, key: str
) -> list[str]:
md = context.invocation_metadata
md = context.invocation_metadata()
raw_values: list[str | bytes] = []
if isinstance(md, Metadata):
raw_values = md.get_all(key)
Comment thread
jubonni marked this conversation as resolved.
Outdated
elif isinstance(md, Sequence):
lower_key = key.lower()
raw_values = [e for (k, e) in md if k.lower() == lower_key]

return [e if isinstance(e, str) else e.decode('utf-8') for e in raw_values]


Expand Down
6 changes: 3 additions & 3 deletions tests/server/request_handlers/test_grpc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ async def test_send_message_with_extensions(
mock_request_handler: AsyncMock,
mock_grpc_context: AsyncMock,
) -> None:
mock_grpc_context.invocation_metadata = grpc.aio.Metadata(
mock_grpc_context.invocation_metadata.return_value = grpc.aio.Metadata(
(HTTP_EXTENSION_HEADER, 'foo'),
(HTTP_EXTENSION_HEADER, 'bar'),
)
Expand Down Expand Up @@ -361,7 +361,7 @@ async def test_send_message_with_comma_separated_extensions(
mock_request_handler: AsyncMock,
mock_grpc_context: AsyncMock,
) -> None:
mock_grpc_context.invocation_metadata = grpc.aio.Metadata(
mock_grpc_context.invocation_metadata.return_value = grpc.aio.Metadata(
(HTTP_EXTENSION_HEADER, 'foo ,, bar,'),
(HTTP_EXTENSION_HEADER, 'baz , bar'),
)
Expand All @@ -386,7 +386,7 @@ async def test_send_streaming_message_with_extensions(
mock_request_handler: AsyncMock,
mock_grpc_context: AsyncMock,
) -> None:
mock_grpc_context.invocation_metadata = grpc.aio.Metadata(
mock_grpc_context.invocation_metadata.return_value = grpc.aio.Metadata(
(HTTP_EXTENSION_HEADER, 'foo'),
(HTTP_EXTENSION_HEADER, 'bar'),
)
Expand Down
Loading