galenwarren commented on a change in pull request #304:
URL: https://github.com/apache/flink-statefun/pull/304#discussion_r814945656



##########
File path: statefun-sdk-go/v3/pkg/statefun/handler.go
##########
@@ -225,11 +225,10 @@ func (h *handler) invoke(ctx context.Context, toFunction 
*protocol.ToFunction) (
                        var cancel context.CancelFunc
                        sContext.Context, cancel = context.WithCancel(ctx)
 
-                       var caller Address
                        if invocation.Caller != nil {

Review comment:
       If I'm thinking about it right, I think the new unit tests demonstrate 
this is working, i.e. they:
   * Create an instance of `protocol.ToFunction`, which contains (among other 
things) the invocations and associated callers (with the caller populated in 
one test and not populated in another test)
   * Serialize that `protocol.ToFunction` to a `[]byte` using `proto.Marshal`
   * Call `handler.Invoke` passing the serialized `protocol.ToFunction`, which 
internally deserializes the `protocol.ToFunction` using `proto.Unmarshal` 
before continuing to process it
   * Validates that the resulting `statefunContext.caller` (via Context.Caller) 
is nil or a not-nil value, according to whether a caller was supplied in the 
original `protocol.ToFunction`
   
   So, if a nil caller in the `protocol.ToFunction` were getting deserialized 
to a non-nil value via `proto.Unmarshal`, that would cause the 
`TestStatefunHandler_WithNoCaller_ContextCallerIsNil` unit test to fail.
   
   Separately, I do a reasonable amount of work with Golang and protobuf, and 
while it's true that, in protobuf 3, primitive fields in messages are not 
deserialized to nil, embedded *message* fields can be deserialized to nil, as 
can repeated values where there are no values. The general rule for protobuf in 
Golang, as I understand it, is that fields not specified in a protobuf message 
are deserialized to the appropriate zero value in the generated Golang structs; 
since nested protobuf messages are generated as *pointers* to structs, the zero 
value used in those cases is nil.
   
   There's some discussion of this 
[here](https://github.com/golang/protobuf/issues/15); in particular, note:
   
   > When the .proto file specifies syntax="proto3", there are some 
differences:  Non-repeated fields of non-message type are values instead of 
pointers.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to