Skip to content

Commit 860f7b1

Browse files
marthjodzhyon404
authored andcommitted
avoid NoneType exception for None handler (#8)
1 parent ce00d0e commit 860f7b1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

python_grpc_prometheus/prometheus_server_interceptor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class PromServerInterceptor(grpc.ServerInterceptor):
4949
def intercept_service(self, continuation, handler_call_details):
5050

5151
handler = continuation(handler_call_details)
52+
if handler is None:
53+
return handler
5254

5355
# only support unary
5456
if handler.request_streaming or handler.response_streaming:

tests/test_prometheus_server_interceptor.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from unittest import TestCase
22
from unittest.mock import Mock
33

4-
from nose.tools import assert_equal
4+
from nose.tools import assert_equal, assert_is_none
55
from parameterized import parameterized
66

77
import requests
@@ -44,6 +44,11 @@ def test_intercept_service_method_name_too_short(self, method):
4444
self.psi.intercept_service(mock_continuation, mock_handler_call_details)
4545
assert_equal(2, mock_continuation.call_count)
4646

47+
def test_none_handler(self):
48+
mock_continuation = Mock(return_value=None)
49+
50+
ret = self.psi.intercept_service(mock_continuation, Mock())
51+
assert_is_none(ret)
4752

4853
class TestServiceLatencyInterceptor(TestCase):
4954
def setUp(self):

0 commit comments

Comments
 (0)