浏览代码

Allow "None" as response message with none-OK status

Lidi Zheng 5 年之前
父节点
当前提交
51e38fa508

+ 4 - 8
src/python/grpcio/grpc/_cython/_cygrpc/aio/server.pyx.pxi

@@ -264,14 +264,10 @@ async def _finish_handler_with_unary_response(RPCState rpc_state,
     rpc_state.raise_for_termination()
 
     # Serializes the response message
-    cdef bytes response_raw
-    if rpc_state.status_code == StatusCode.ok:
-        response_raw = serialize(
-            response_serializer,
-            response_message,
-        )
-    else:
-        response_raw = b''
+    cdef bytes response_raw = serialize(
+        response_serializer,
+        response_message,
+    )
 
     # Assembles the batch operations
     cdef tuple finish_ops

+ 4 - 1
src/python/grpcio/grpc/_cython/_cygrpc/operation.pyx.pxi

@@ -49,7 +49,10 @@ cdef class SendInitialMetadataOperation(Operation):
 cdef class SendMessageOperation(Operation):
 
   def __cinit__(self, bytes message, int flags):
-    self._message = message
+    if message is None:
+      self._message = b''
+    else:
+      self._message = message
     self._flags = flags
 
   def type(self):