Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-5264

Argument requiredness and field requiredness



    • Question
    • Status: Resolved
    • Major
    • Resolution: Done
    • 0.13.0
    • None
    • Compiler (General)
    • None


      I have two questions regarding the requiredness in the generated code.

      1. Argument requiredness is ignored

      When defining a method 

      string echo(1: optional string msg)


      optional keyword is ignored in argument lists. 

      We would like to ask about the future plan of supporting argument requiredness.
      Full context: our team maintains a Thrift code generator built upon Apache Thrift, Scrooge, which now respects the optional keyword in the argument list and generates an Optional argument. We want to align with the libthrift's future plan to reduce potential incompatible issues.

      2. Field requiredness is unmatched across languages

      We noticed that Apache Thrift generated different behavioral code for different languages.

      Taking this as an example

      struct TestRequiredness {
       1: i32 A
       2: required i32 B
       3: optional i32 C

      Generated Java code has 3 different read/write requiredness combinations for all three, and they are what we expected. OptInReqOut: optional write and required Read, Required: required on both read and write, Optional: optional on both read and write.

      However, the generated Python code treats all three the same: Optional read and write. (there is a validate method checking for B, but doesn't seem to be forced on either read or write path).

      After a quick skim, it seems the generated PHP code has the same behavior as Python.

      Assuming python client talking to java server with required fields set, this could cause the TProtocolExceptions being propagated to the server, while python client should catch them earlier.





            jensg Jens Geyer
            ygong Yufan Gong
            0 Vote for this issue
            2 Start watching this issue