Skip to content

Commit

Permalink
Skip interceptor for methods that are not registered in the server
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga committed Nov 15, 2023
1 parent af11a9b commit 34d8efa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/grpc_interceptor/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ async def intercept_service(self, continuation, handler_call_details):
have a public name. Do not override it, unless you know what you're doing.
"""
next_handler = await continuation(handler_call_details)
# Returns None if the method isn't implemented.
if not next_handler:
return

handler_factory, next_handler_method = _get_factory_and_method(next_handler)

if next_handler.response_streaming:
Expand Down
10 changes: 7 additions & 3 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,19 @@ def test_aborting_interceptor(aio):
assert e.value.details() == "oh no"


def test_method_not_found():
@pytest.mark.parametrize("aio", [False, True])
def test_method_not_found(aio):
"""Calling undefined endpoints should return Unimplemented.
Interceptors are not invoked when the RPC call is not handled.
"""
intr = CountingInterceptor()
intr_type = AsyncCountingInterceptor if aio else CountingInterceptor
intr = intr_type()
interceptors = [intr]

with dummy_channel(special_cases={}, interceptors=interceptors) as channel:
with dummy_channel(
special_cases={}, interceptors=interceptors, aio_server=aio
) as channel:
with pytest.raises(grpc.RpcError) as e:
channel.unary_unary(
"/DummyService/Unimplemented",
Expand Down

0 comments on commit 34d8efa

Please sign in to comment.