[
https://issues.apache.org/jira/browse/THRIFT-3533?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15090984#comment-15090984
]
Chris Bannister commented on THRIFT-3533:
-----------------------------------------
In python you can write this,
service.method(None) which works fine, but in go if you do service.method(nil)
it panics.
Im not sure which is correct.
This is the code from github.com/apache/aurora api.thrift for create_job
args.Write in python,
{code}
def write(self, oprot):
if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and
self.thrift_spec is not None and fastbinary is not None:
oprot.trans.write(fastbinary.encode_binary(self, (self.__class__,
self.thrift_spec)))
return
oprot.writeStructBegin('createJob_args')
if self.description is not None:
oprot.writeFieldBegin('description', TType.STRUCT, 1)
self.description.write(oprot)
oprot.writeFieldEnd()
if self.lock is not None:
oprot.writeFieldBegin('lock', TType.STRUCT, 3)
self.lock.write(oprot)
oprot.writeFieldEnd()
oprot.writeFieldStop()
oprot.writeStructEnd()
{/code}
and In Go it looks like this
{code}
func (p *AuroraSchedulerManagerCreateJobArgs) Write(oprot thrift.TProtocol)
error {
if err := oprot.WriteStructBegin("createJob_args"); err != nil {
return thrift.PrependError(fmt.Sprintf("%T write struct begin
error: ", p), err)
}
if err := p.writeField1(oprot); err != nil {
return err
}
if err := p.writeField3(oprot); err != nil {
return err
}
if err := oprot.WriteFieldStop(); err != nil {
return thrift.PrependError("write field stop error: ", err)
}
if err := oprot.WriteStructEnd(); err != nil {
return thrift.PrependError("write struct stop error: ", err)
}
return nil
}
{code}
Go will insert the 'x.IsSet' for optional fields, but args can't be optional.
> Can not send nil pointer as service method argument
> ---------------------------------------------------
>
> Key: THRIFT-3533
> URL: https://issues.apache.org/jira/browse/THRIFT-3533
> Project: Thrift
> Issue Type: Bug
> Components: Go - Compiler
> Affects Versions: 0.9.3
> Reporter: Chris Bannister
>
> If you try to send a nil struct as an argument to a service method a panic
> occurs as it tries to write out all the fields in the struct, the python
> generated code has guarding 'if self.x != None:' for every struct field,
> whereas Go only outputs the 'if p.IsSet()' when the field is declared
> optional, which is not possible for argument lists.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)