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

python enum fields with specified default value not serializable

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • Python - Compiler
    • None

    Description

      In the generated Python code, default values for enums are set as enum objects (ie, <name: value>), but thrift objects expect this value to be stored either by its name or its value. This results in a keyerror during the write method. 

      For example, if I have the following thrift schema

       

      enum MyEnum {
        test_a,
        test_b,
        test_c
      }
      struct MyStruct {
        1: MyEnum enum_field = MyEnum.test_c
      }
       
      

      and then in the python code:

      new_struct = MyStruct()
      thrift.TSerialization.serialize(new_struct)
      

      it'd get a `keyerror` from the code generated here 

      oprot.writeI32(MyEnum[new_struct.enum_field].value)
        File "[my-path]/lib/python3.9/enum.py", line 432, in __getitem__
          return cls._member_map_[name]
      KeyError: <MyEnum.test_c: 2> 

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              acunningham Andrew Cunningham
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 50m
                  1h 50m