[ 
https://issues.apache.org/jira/browse/THRIFT-5885?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jens Geyer resolved THRIFT-5885.
--------------------------------
    Fix Version/s: 0.23.0
       Resolution: Fixed

> TBinaryProtocolAccelerated incorrectly deserializes IntEnum to None
> -------------------------------------------------------------------
>
>                 Key: THRIFT-5885
>                 URL: https://issues.apache.org/jira/browse/THRIFT-5885
>             Project: Thrift
>          Issue Type: Bug
>          Components: Python - Compiler, Python - Library
>    Affects Versions: 0.22.0
>         Environment: thrift==0.22.0
>            Reporter: Adrian Stachlewski
>            Assignee: Carel
>            Priority: Major
>             Fix For: 0.23.0
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> When using {{TBinaryProtocolAccelerated}}, {{IntEnum}} fields are incorrectly 
> deserialized to {{None}}.
> This issue occurs when the {{read}} function is executed via 
> {{\_fast_decode}}. In this path, the custom deserialization logic 
> {{CustomEnum(iprot.readI32())}} is skipped. Instead, an integer value 
> ({{i32}}) is directly passed to {{\_\_setattr\_\_}}, where the value is 
> resolved using:
> {code:python}
> Operation.__members__.get(value) {code}
> However, {{\_\_members\_\_}} maps enum names (not values) to enum members, 
> which results in the call returning None. This leads to the enum field being 
> set to {{None}} instead of the expected enum instance. A minimal and 
> effective fix could be to update the {{\_\_setattr\_\_}} method logic to:
> {code:python}
> if name == "enum_field":
>     super().__setattr__(name, value if hasattr(value, 'value') or value is 
> None else Operation(value)) {code}
> This would ensure that the enum value is correctly reconstructed from its 
> integer representation during deserialization.
>  



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

Reply via email to