Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add None check for grpc.aio interceptor #3109

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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: 4 additions & 2 deletions sentry_sdk/integrations/grpc/aio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

if TYPE_CHECKING:
from collections.abc import Awaitable, Callable
from typing import Any
from typing import Any, Optional


try:
Expand All @@ -26,9 +26,11 @@ def __init__(self, find_name=None):
super().__init__()

async def intercept_service(self, continuation, handler_call_details):
# type: (ServerInterceptor, Callable[[HandlerCallDetails], Awaitable[RpcMethodHandler]], HandlerCallDetails) -> Awaitable[RpcMethodHandler]
# type: (ServerInterceptor, Callable[[HandlerCallDetails], Awaitable[RpcMethodHandler]], HandlerCallDetails) -> Optional[Awaitable[RpcMethodHandler]]
self._handler_call_details = handler_call_details
handler = await continuation(handler_call_details)
if handler is None:
return None

if not handler.request_streaming and not handler.response_streaming:
handler_factory = grpc.unary_unary_rpc_method_handler
Expand Down
23 changes: 23 additions & 0 deletions tests/integrations/grpc/test_grpc_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,29 @@ def event_loop(request):
loop.close()


@pytest.mark.asyncio
async def test_noop_for_unimplemented_method(sentry_init, capture_events, event_loop):
sentry_init(traces_sample_rate=1.0, integrations=[GRPCIntegration()])
server = grpc.aio.server()
server.add_insecure_port("[::]:{}".format(AIO_PORT))

await event_loop.create_task(server.start())

events = capture_events()
try:
async with grpc.aio.insecure_channel(
"localhost:{}".format(AIO_PORT)
) as channel:
stub = gRPCTestServiceStub(channel)
with pytest.raises(grpc.RpcError) as exc:
await stub.TestServe(gRPCTestMessage(text="test"))
assert exc.value.details() == "Method not found!"
finally:
await server.stop(None)

assert not events


@pytest_asyncio.fixture(scope="function")
async def grpc_server(sentry_init, event_loop):
sentry_init(traces_sample_rate=1.0, integrations=[GRPCIntegration()])
Expand Down
Loading