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

Generated code gets overwritten if namespace is shared across multiple IDL files

    XMLWordPrintableJSON

Details

    • Important

    Description

      If multiple .thrift files in the same directory share a python namespace and struct definitions exist in more than one of those files, then ONLY the structs in the first targeted .thrift file get generated. Services defined in each file are generated, though, which results in a NameError when importing that service.

      Ex:

      ~/proj/d/a.thrift
      namespace java com.p.api
      namespace py p_different.api.net
      namespace cpp p.api
      
      include "../model/Common.thrift"
      
      struct ARequest
      {
      1: required i64 ID;
      }
      
      struct AResponse
      {
      1: required i64 ID;
      }
      
      service AService
      {
       AResponse
       save(1: Common.Context ctx, 2: ARequest req)
       throws (1: Common.Exception e);
      }
      
      ~/proj/d/b.thrift
      namespace java com.p.api
      namespace py p_different.api.net 
      namespace cpp p.api
      
      include "../model/Common.thrift"
      
      struct BRequest
      {
      1: required i64 ID;
      }
      
      struct BResponse
      {
      1: required i64 ID;
      }
      
      service BService
      {
       BResponse
       save(1: Common.Context ctx, 2: BRequest req)
       throws (1: Common.Exception e);
      }
      

      The A* service and structs are successfully generated in python and all works well. However, while BService gets generated successfully, when one tries to import BService, a NameError is thrown for BRequest not having a definition.

      I've grep'd the genereated sources and sure enough, there's no class declaration for BRequest nor BResponse.

      If I append the py namespace with a subnamespace, then all works well, but I wonder if this is the intended behavior which I doubt because the compiler doesn't barf.

      Attachments

        Activity

          People

            jensg Jens Geyer
            jaronhalt Jeffery Aronhalt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: