You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Chandler May (JIRA)" <ji...@apache.org> on 2017/01/05 17:46:58 UTC

[jira] [Updated] (THRIFT-4020) UnboundLocalError for optional field in read of immutable type

     [ 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)