In proto3 message fields (such as the "book" field in this case) do have
field presence. You are not supposed to check it with None though, because
if the field is not present, getters are supports to return a default
instance. There is another HasField() method to be used to check whether
the field is present or not. Try:

resp.HasField("book")   # should be false if the server returns an empty
response.

See:
https://developers.google.com/protocol-buffers/docs/reference/python-generated#embedded_message

On Thu, Nov 24, 2016 at 4:28 PM, Jesús García Crespo <[email protected]>
wrote:

> Hi again,
>
> On Wed, Nov 23, 2016 at 6:24 PM, Nathaniel Manista <[email protected]>
> wrote:
>
>> possibly a oneof
>> <https://developers.google.com/protocol-buffers/docs/proto#using-oneof> that
>> can communicate exactly one of the id of a found book or the fact that the
>> book was not found.
>
>
> This makes sense to me, I'll give it a shot!
>
>
>> 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?
>>>
>>
>> I think this has to do with the changes in Protocol Buffers 3 and how
>> fields and messages are never "not present" any more.
>>
>
> Ok, I'm glad to know that was conscious choice and not a bug in my code :)
>
> Thank you so much,
>
> --
> Jesús García Crespo
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" 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/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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/CABpao3p5iXvxe8yBZCLLyU7G4mwwPSsOO3d2F3e3w%2BWcKOb_Kg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to