[
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075348#comment-16075348
]
Eric Conner edited comment on THRIFT-2642 at 7/5/17 8:27 PM:
-------------------------------------------------------------
Hi [~jensg],
Thanks for the follow up. This pull request
https://github.com/apache/thrift/pull/1293 is my attempt at a fix (which I
linked above). Can someone review it?
I also outlined the approach above. Copied here:
I followed the fbthrift approach. At a high level, the change
Moves all thrift_spec definitions to the end of the ttypes file. Or, in the
case of a service, after the service definition.
Changes the initial declaration of the spec for a TStruct to [<Struct>, None]
Uses a method call ``fix_spec`` to fill in the spec to [<Struct>,
<Struct>.thrift_spec]
I should note that this does not solve the case of co-recursive structures, a
problem that fbthrift also suffers from. Co-recursive structs can be created
but they cannot be serialized or deserialized (leads to infinite loop).
was (Author: econner724):
Hi [~jensg],
Thanks for the follow up. This pull request
https://github.com/apache/thrift/pull/1293 is my attempt at a fix (which I
linked above). Can someone review it?
I also outlined the approach above. Copied here:
I followed the fbthrift approach. At a high level, the change
Moves all thrift_spec definitions to the end of the ttypes file. Or, in the
case of a service, after the service definition.
Changes the initial declaration of the spec for a TStruct to [<Struct>, None]
Uses a method call ``fix_spec`` to fill in the spec to [<Struct>,
<Struct>.thrift_spec]
I should note that this does not solve the case of co-recursive structures, a
problem that fbthrift also suffers from.
> Recursive structs don't work in python
> --------------------------------------
>
> Key: THRIFT-2642
> URL: https://issues.apache.org/jira/browse/THRIFT-2642
> Project: Thrift
> Issue Type: Bug
> Components: Python - Compiler, Python - Library
> Affects Versions: 0.9.2
> Reporter: Igor Kostenko
>
> Recursive structs in 0.9.2 work fine in c++ & c#, but not in python, because
> generated code trying to use objects which not constructed yet.
> Struct:
> {code}
> struct Recursive {
> 1: list<Recursive> Children
> }
> {code}
> Python code:
> {code}
> class Recursive:
> thrift_spec = (
> None, # 0
> (1, TType.LIST, 'Children', (TType.STRUCT,(Recursive,
> Recursive.thrift_spec)), None, ), # 1
> )
> {code}
> Error message:
> {code}
> Traceback (most recent call last):
> File "ttypes.py", line 20, in <module>
> class Recursive:
> File "ttypes.py", line 28, in Recursive
> (1, TType.LIST, 'Children', (TType.STRUCT,(Recursive,
> Recursive.thrift_spec)), None, ), # 1
> NameError: name 'Recursive' is not defined
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)