Andrew Cunningham created THRIFT-5693:
-----------------------------------------

             Summary: [python] enum fields with specified default value not 
serializable
                 Key: THRIFT-5693
                 URL: https://issues.apache.org/jira/browse/THRIFT-5693
             Project: Thrift
          Issue Type: Bug
            Reporter: Andrew Cunningham


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

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

and then in the python code:

 
{code:java}
new_struct = MyStruct()
thrift.TSerialization.serialize(new_struct)
{code}
 

 

it'd get a `keyerror` from the code generated 
[here|https://github.com/apache/thrift/blob/0.17.0/compiler/cpp/src/thrift/generate/t_py_generator.cc#L2479]
 where the `name` value passed in would be <test_c, 2>



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to