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

Having the same namespace in separate thrift files generates non-working code

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Not A Problem
    • None
    • None
    • Python - Compiler
    • None

    Description

      If there are two thrift files which use the same namespace the generated python code does not work. A sample case is the two thrift files provided below:

      -------test.thrift---------
      namespace py Sample

      struct Name {
      1: string n
      }

      struct User {
      1: i32 id,
      2: Name user_name
      }
      -------- end test.thrift----------

      -------test_service.thrift----------

      include "test.thrift"

      namespace py Sample

      service TestService {
      test.User get_user(1: i64 id),
      test.Name get_user_name(1: i64 id),
      }
      -------end test_service.thrift----------

      This happens because the ttypes for test.thrift are clobbered by the ttypes for TestService. As a result TestService is not imported correctly.

      >>> import Sample
      >>> import Sample.ttypes
      >>> from Sample import *
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "Sample/TestService.py", line 205, in <module>
      class get_user_result:
      File "Sample/TestService.py", line 212, in get_user_result
      (0, TType.STRUCT, 'success', (Sample.ttypes.User, Sample.ttypes.User.thrift_spec), None, ), # 0
      AttributeError: 'module' object has no attribute 'User'

      Attachments

        Activity

          People

            jensg Jens Geyer
            jkupferman Jonathan Kupferman
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: