Hi everyone,

First, I would like to say thanks to all of you for the great job!
I'm trying to wire two Python apps using grpcio 1.0.1. In the scenario that
I'm going to describe below, the client asks for a determined book and the
server wants to communicate that the book has not ben found. What would be
the current way to do that with the following proto?

service Library {
  rpc BookGet(BookGetRequest) returns (BookGetResponse)
}

message Book {
  string id = 1;
}

message BookGetRequest {
  string id = 1;
}

message BookGetResponse {
  Book book = 1;
}

I've tried the following snippet but it won't work because I can't return
`None` or the channel will fail to serialize the response:

class LibraryServer(object):
    def BookGet(self, request, context):
        """ Book not found. """
        context.set_code(grpc.StatusCode.NOT_FOUND)

If I return an empty message *and* set the status code to NOT_FOUND then I
see an internal exception (message = "_Rendezvous of RPC that terminated
with (StatusCode.NOT_FOUND, )") is raised on the client side:

class LibraryServer(object):
    def BookGet(self, request, context):
        """ Book not found. """
        context.set_code(grpc.StatusCode.NOT_FOUND)

I've also attempted these two approaches:

class LibraryServer(object):
    def BookGet(self, request, context):
        """ Book not found. """
        return library_mcp2.BookGetResponse()

class LibraryServer(object):
    def BookGet(self, request, context):
        """ Book not found. """
        return library_mcp2.BookGetResponse(book=None)

However, this is what I am seeing on the client:

resp = self.stub.BookGet(library_pb2.BookGetRequest(id='12345'))
resp is None          # False
resp.book is None     # False
resp.book.id is None  # False
resp.book.id == ''    # True

So I could only make use of the last assertion but that seems far from
ideal, right? What am I doing wrong?

Thank you for your help!

-- 
Jesús García Crespo

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CA%2BunNDJiScR%2Bd4QNKk%2B804uKmVdU%2Bp_%2BZ-KG-yZgeaSh0vHMPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to