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

Chandler May updated THRIFT-4020:
---------------------------------
    Description: 
During the read method of a structure annotated as immutable, if the value of 
an optional field is not read (if it is unset in the serialized structure) an 
UnboundLocalError is thrown when the class is instantiated.

This is caused by storing the deserialized fields in local variables declared 
in nested scopes and instantiating the structure at the end of the read method: 
if an optional field is not set in the serialized object, the variable storing 
its deserialized representation (in this case, None) is never declared.

I think this would be fixed by declaring variables for all fields at the top of 
the read method, initializing them to their defaults in thrift_spec.

  was:
During the read method of a structure annotated as immutable, if the value of 
an optional field is not read (if it is unset in the serialized structure) an 
UnboundLocalError is thrown when the class is instantiated.

This is caused by storing the deserialized fields in local variables declared 
in nested scopes and instantiating the structure at the end of the read method: 
if an optional field is not set in the serialized object, the variable storing 
its deserialized representation---in this case, None---is never declared.

I think this would be fixed by declaring variables for all fields at the top of 
the read method, initializing them to their defaults in thrift_spec.


> UnboundLocalError for optional field in read of immutable type
> --------------------------------------------------------------
>
>                 Key: THRIFT-4020
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4020
>             Project: Thrift
>          Issue Type: Bug
>          Components: Python - Compiler
>    Affects Versions: 0.10.0
>            Reporter: Chandler May
>
> During the read method of a structure annotated as immutable, if the value of 
> an optional field is not read (if it is unset in the serialized structure) an 
> UnboundLocalError is thrown when the class is instantiated.
> This is caused by storing the deserialized fields in local variables declared 
> in nested scopes and instantiating the structure at the end of the read 
> method: if an optional field is not set in the serialized object, the 
> variable storing its deserialized representation (in this case, None) is 
> never declared.
> I think this would be fixed by declaring variables for all fields at the top 
> of the read method, initializing them to their defaults in thrift_spec.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to