[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-06 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16077195#comment-16077195
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user asfgit closed the pull request at:

https://github.com/apache/thrift/pull/1293


> 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
>Assignee: Eric Conner
> Fix For: 0.11.0
>
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-06 Thread julien greard (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16076684#comment-16076684
 ] 

julien greard commented on THRIFT-2642:
---

Just did it, looks fine to me




> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-06 Thread Eric Conner (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16076667#comment-16076667
 ] 

Eric Conner commented on THRIFT-2642:
-

Ok [~juliengreard] I believe I have addressed all of your comments.  Would you 
mind taking another look?

Thanks.

> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075576#comment-16075576
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user econner commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1293#discussion_r125776924
  
--- Diff: lib/py/src/ext/types.cpp ---
@@ -20,6 +20,8 @@
 #include "ext/types.h"
 #include "ext/protocol.h"
 
+#include 
--- End diff --

Mm I believe this was a holdover from testing & using print statements.  It 
should be safe to remove.  Thanks for catching.


> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075577#comment-16075577
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user econner commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1293#discussion_r125777018
  
--- Diff: test/py/SerializationTest.py ---
@@ -285,6 +290,67 @@ def testIntegerLimits(self):
 for value in bad_values:
 self.assertRaises(Exception, self._serialize, value)
 
+def testRecTree(self):
+"""Ensure recursive tree node can be created."""
+children = []
+for idx in range(1, 5):
--- End diff --

This is just a test to ensure you can make a tree with some children.  
There is no limit on the number of recursions (I guess besides the maximum 
allowed by python).


> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075575#comment-16075575
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user econner commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1293#discussion_r125776706
  
--- Diff: compiler/cpp/src/thrift/generate/t_py_generator.cc ---
@@ -610,11 +623,22 @@ string t_py_generator::render_const_value(t_type* 
type, t_const_value* value) {
   return out.str();
 }
 
+/** 
+ * Generates the "forward declarations" for python structs.
+ * These are actually full class definitions so that calls to 
generate_struct
+ * can add the thrift_spec field.  This is needed so that all thrift_spec 
+ * definitions are grouped at the end of the file to enable co-recursive 
structs.
+ */
+void t_py_generator::generate_forward_declaration(t_struct* tstruct) {
--- End diff --

This is an interface method that's called by the thrift compiler.  One 
attribute of this change is to move most of the code that generates python code 
into ``generate_forward_declaration`` and then output the ``thrift_spec`` via 
the ``generate_struct`` method.


> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread julien greard (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075536#comment-16075536
 ] 

julien greard commented on THRIFT-2642:
---

Ok it should be better now !




> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075531#comment-16075531
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user juliengreard commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1293#discussion_r125757042
  
--- Diff: compiler/cpp/src/thrift/generate/t_py_generator.cc ---
@@ -610,11 +623,22 @@ string t_py_generator::render_const_value(t_type* 
type, t_const_value* value) {
   return out.str();
 }
 
+/** 
+ * Generates the "forward declarations" for python structs.
+ * These are actually full class definitions so that calls to 
generate_struct
+ * can add the thrift_spec field.  This is needed so that all thrift_spec 
+ * definitions are grouped at the end of the file to enable co-recursive 
structs.
+ */
+void t_py_generator::generate_forward_declaration(t_struct* tstruct) {
+generate_py_struct(tstruct, tstruct->is_xception());
+}
+
 /**
  * Generates a python struct
  */
 void t_py_generator::generate_struct(t_struct* tstruct) {
-  generate_py_struct(tstruct, false);
+  //generate_py_struct(tstruct, false);
--- End diff --

bad idea to leave commented code - if you really want to leave it there, 
leave also a comment explaining why


> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075532#comment-16075532
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user juliengreard commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1293#discussion_r125757570
  
--- Diff: compiler/cpp/src/thrift/generate/t_py_generator.cc ---
@@ -634,6 +659,49 @@ void t_py_generator::generate_py_struct(t_struct* 
tstruct, bool is_exception) {
   generate_py_struct_definition(f_types_, tstruct, is_exception);
 }
 
+
+/**
+ * Generate the thrift_spec for a struct
+ * e.g. (4, TType.LIST, 'struct_list', (TType.STRUCT, (RandomStuff, None), 
False), None, ),  # 4
+ */
+void t_py_generator::generate_py_thrift_spec(ofstream& out,
+ t_struct* tstruct,
+ bool /*is_exception*/) {
+  const vector& sorted_members = tstruct->get_sorted_members();
+  vector::const_iterator m_iter;
+
+  // Add struct definition to list so thrift_spec can be fixed for 
recursive structures.
+  indent(out) << "all_structs.append(" << tstruct->get_name() << ")" << 
endl;
+
+  if (sorted_members.empty() || (sorted_members[0]->get_key() >= 0)) {
+indent(out) << tstruct->get_name() << ".thrift_spec = (" << endl;
+indent_up();
+
+int sorted_keys_pos = 0;
+for (m_iter = sorted_members.begin(); m_iter != sorted_members.end(); 
++m_iter) {
+
+  for (; sorted_keys_pos != (*m_iter)->get_key(); sorted_keys_pos++) {
+indent(out) << "None,  # " << sorted_keys_pos << endl;
+  }
+
+  indent(out) << "(" << (*m_iter)->get_key() << ", " << 
type_to_enum((*m_iter)->get_type())
--- End diff --

a comment showing an example of the python code generated from this peace 
of code would be a plus


> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075528#comment-16075528
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user juliengreard commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1293#discussion_r125761010
  
--- Diff: test/py/SerializationTest.py ---
@@ -285,6 +290,67 @@ def testIntegerLimits(self):
 for value in bad_values:
 self.assertRaises(Exception, self._serialize, value)
 
+def testRecTree(self):
+"""Ensure recursive tree node can be created."""
+children = []
+for idx in range(1, 5):
--- End diff --

where do the "5" comes from ? Is it a limit for the implementation (you 
can't have recursive struct with more than 5 recursions? if so, it should be 
highlighted (maybe it is already, but I didn't see it). What happens if I have 
a struct with more than 5 recursions in it (i.e. 
myObject.leaf.leaf.leaf.leaf.leaf.leaf.leaf.leaf is not None)?


> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075529#comment-16075529
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user juliengreard commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1293#discussion_r125756848
  
--- Diff: compiler/cpp/src/thrift/generate/t_py_generator.cc ---
@@ -610,11 +623,22 @@ string t_py_generator::render_const_value(t_type* 
type, t_const_value* value) {
   return out.str();
 }
 
+/** 
+ * Generates the "forward declarations" for python structs.
+ * These are actually full class definitions so that calls to 
generate_struct
+ * can add the thrift_spec field.  This is needed so that all thrift_spec 
+ * definitions are grouped at the end of the file to enable co-recursive 
structs.
+ */
+void t_py_generator::generate_forward_declaration(t_struct* tstruct) {
--- End diff --

I dont't see where this function is called. Maybe I don't have the full 
diff in front of me


> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075527#comment-16075527
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user juliengreard commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1293#discussion_r125759386
  
--- Diff: lib/py/src/ext/types.cpp ---
@@ -20,6 +20,8 @@
 #include "ext/types.h"
 #include "ext/protocol.h"
 
+#include 
--- End diff --

I usually include built-in lib first


> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075530#comment-16075530
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user juliengreard commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1293#discussion_r125759228
  
--- Diff: lib/py/src/TRecursive.py ---
@@ -0,0 +1,63 @@
+# MODIFIED June 20, 2017, Eric Conner
+#
+#
+# Original source copyright 2014-present Facebook, Inc.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from __future__ import absolute_import
+from __future__ import division
+from __future__ import print_function
+from __future__ import unicode_literals
+
+from thrift.Thrift import TType
+
+
+def fix_spec(all_structs):
--- End diff --

Well I'm sorry but I dont understand this file. Maybe explaining what the 
functions are doing would help. You could also use named variables instead of 
using directly 'magic' numbers (like const static int name = 1). But I may be 
wrong, I'm a complete stranger to the source code of thrift, so maybe it's the 
way to do it


> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread Eric Conner (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075519#comment-16075519
 ] 

Eric Conner commented on THRIFT-2642:
-

Hi Julien,
I cannot see your comments.  Did you submit them via github?  Or somewhere else?
Thank you.

> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread julien greard (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075452#comment-16075452
 ] 

julien greard commented on THRIFT-2642:
---

Ok it's done, do you see my comments/reviews?




> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread julien greard (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075429#comment-16075429
 ] 

julien greard commented on THRIFT-2642:
---

Hi,
I'll try a review, but it's my first one on github and I don't know thrift
source code well, so forgive me if I'm wrong ;-)




> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075394#comment-16075394
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user econner commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1293#discussion_r125751862
  
--- Diff: lib/py/src/TRecursive.py ---
@@ -0,0 +1,63 @@
+# MODIFIED June 20, 2017, Eric Conner
+#
+#
+# Original source copyright 2014-present Facebook, Inc.
+#
--- End diff --

Yea, I'm not very experienced with the whole issue of licensing.  I mainly 
put these lines because of the fbthrift license and I used this file more or 
less verbatim from fbthrift.  
(https://github.com/facebook/fbthrift/blob/master/LICENSE#L97) 
(https://github.com/facebook/fbthrift/blob/master/thrift/lib/py/util/Recursive.py)

>   (b) You must cause any modified files to carry prominent notices
  stating that You changed the files; and

  (c) You must retain, in the Source form of any Derivative Works
  that You distribute, all copyright, patent, trademark, and
  attribution notices from the Source form of the Work,
  excluding those notices that do not pertain to any part of
  the Derivative Works; and

But perhaps it is fine to use verbatim since fbthrift is itself a branch of 
thrift?  Not really sure what the protocol here is...


> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075370#comment-16075370
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user Jens-G commented on a diff in the pull request:

https://github.com/apache/thrift/pull/1293#discussion_r125749743
  
--- Diff: lib/py/src/TRecursive.py ---
@@ -0,0 +1,63 @@
+# MODIFIED June 20, 2017, Eric Conner
+#
+#
+# Original source copyright 2014-present Facebook, Inc.
+#
--- End diff --

Where does line 1 to 5 come from? That's not part of the standard ASF 
license header.


> 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
>Assignee: Eric Conner
>
> 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 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 
> 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)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread Jens Geyer (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075360#comment-16075360
 ] 

Jens Geyer commented on THRIFT-2642:


> 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?

Hi [~isanych] and [~juliengreard] could you help out?


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


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread Eric Conner (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075348#comment-16075348
 ] 

Eric Conner commented on THRIFT-2642:
-

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 [, None]
Uses a method call ``fix_spec`` to fill in the spec to [, 
.thrift_spec]




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


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread Jens Geyer (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16075330#comment-16075330
 ] 

Jens Geyer commented on THRIFT-2642:


> I think that's thrift should be  working the same no matter the language 
> (that's the point of thrift I believe).

Yep.

> disable recursive structures for everyone

Ehm, no. :)

A bit of history and background may help: This particular feature has been 
added based on the impl in fbthrift, and it is one of the additions with the 
most impact on Thrift in my opinion. But since Thrift's target language base is 
much larger compare to fbthrift, we unfortunately do not yet have suitable 
support in some of them, e.g. Python. 

There are similar other features that do also not have broad language support, 
for several reasons. For example, the THeader stuff is currently only available 
for C++. Nevertheless, the fact that not all > 20 languages do offer it *today* 
does not imply that we will throw it out. It is a cool feature, and whoever 
needs it for his language of choice will contribute a patch sooner or later. 
That's how open source works. It doesn't have to be perfect from the beginning 
(which is especially a stretching goal if there is a target language base as 
large as Thrift's). 

So my favourite would be:

> make it work for Python

However I would be a bad implementor, because I very rarely use Python myself 
and I probably only make it worse. But what if you two guys take a stab on it 
together? Could that work? What do you think? Anyone else reading this who 
wants to try his luck?




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


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread julien greard (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16074792#comment-16074792
 ] 

julien greard commented on THRIFT-2642:
---

 Hi,

My company uses thrift & python. We use a workaround for the recursive
structures and it's kind of works but I think that's thrift should be
working the same no matter the language (that's the point of thrift I
believe).

In my opinion, there are 3 options:
- disable recursive structures for everyone
- make it work for Python
- live with it as we do for now, but a bug like that shows a bad image and
will possibly make someone who uses thrift switch to another language,
isn't it?






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


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-07-05 Thread Eric Conner (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16074774#comment-16074774
 ] 

Eric Conner commented on THRIFT-2642:
-

Hi everyone,
Just curious if there's still any desire to get this working.

Here's the PR: https://github.com/apache/thrift/pull/1293

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


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-06-21 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16057856#comment-16057856
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user econner commented on the issue:

https://github.com/apache/thrift/pull/1293
  
Ok, I've updated the PR to use a list (reference type) instead of a tuple.  
I also added some serialization tests for recursive structures. Hopefully 
everything works now.


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


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-06-21 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16057851#comment-16057851
 ] 

ASF GitHub Bot commented on THRIFT-2642:


GitHub user econner reopened a pull request:

https://github.com/apache/thrift/pull/1293

THRIFT-2642 Recursive structs don't work in python

See https://issues.apache.org/jira/browse/THRIFT-2642.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/econner/thrift master

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/thrift/pull/1293.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #1293


commit d62798144b68353c8def2e80388b9ae5e368e9fb
Author: Eric Conner 
Date:   2017-06-21T01:34:12Z

THRIFT-2642 Recursive structs don't work in python

See https://issues.apache.org/jira/browse/THRIFT-2642.

commit b178f8109e6a0f94005ed65db506e2b14ac41a9d
Author: Eric Conner 
Date:   2017-06-21T14:52:44Z

Fix build issues.

commit 7eb8e319385185904161185602f902bee0ff4544
Author: Eric Conner 
Date:   2017-06-21T17:00:57Z

Convert spec for TStruct to list in python.




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


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-06-21 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16057819#comment-16057819
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user econner commented on the issue:

https://github.com/apache/thrift/pull/1293
  
As written this will not work.  The spec for a Struct needs to be a 
reference type such as a list for recursion to work correctly so there is more 
work to be done here.


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


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-06-21 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16057820#comment-16057820
 ] 

ASF GitHub Bot commented on THRIFT-2642:


Github user econner closed the pull request at:

https://github.com/apache/thrift/pull/1293


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


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-06-21 Thread julien greard (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16057106#comment-16057106
 ] 

julien greard commented on THRIFT-2642:
---

Hi

Thanks for the work, I'll have a look this week. I don't know yet how to
review code on JIRA but I'm sure it's well documented.





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


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-06-20 Thread Eric Conner (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16056824#comment-16056824
 ] 

Eric Conner commented on THRIFT-2642:
-

Hi everyone,

I finally had some time to take a stab at fixing this.  

I more or less followed the fbthrift approach with a few modifications.  At a 
high level, the change:

# Moves all thrift_spec definitions to the end of the ttypes or service file.
# Changes the initial declaration of thrift_spec to (, None) 
# Uses a method call ``fix_spec`` to fill in the spec to (, 
.thrift_spec)

The fbthrift approach is similar except their struct definition uses a list 
[, .thrift_spec].  I looked at this route for awhile, but 
Apache Thrift's fastbinary implementation depends pretty heavily on 
``thrift_spec`` being immutable.  There are ref counting assumptions I don't 
fully understand that led to lots of complications when I tried to change 
things to use lists (see 
https://github.com/apache/thrift/blob/19baeefd8c38d62085891d7956349601f79448b3/lib/py/src/ext/protocol.tcc#L341).

Instead, I'm using a modified version of fbthrift's fix_spec script 
(https://github.com/facebook/fbthrift/blob/3ef868c969464e935b39e336807af1486b2739c3/thrift/lib/py/util/Recursive.py).
  The main change I made was to convert each spec to a list, modify the list 
recursively, and then convert the list back to a tuple.  I'm unsure of the 
performance hit this adds, but I figured it wouldn't be too bad since it only 
happens at import time.

 
 







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


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-06-20 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16056825#comment-16056825
 ] 

ASF GitHub Bot commented on THRIFT-2642:


GitHub user econner opened a pull request:

https://github.com/apache/thrift/pull/1293

THRIFT-2642 Recursive structs don't work in python

See https://issues.apache.org/jira/browse/THRIFT-2642.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/econner/thrift master

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/thrift/pull/1293.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #1293


commit d62798144b68353c8def2e80388b9ae5e368e9fb
Author: Eric Conner 
Date:   2017-06-21T01:34:12Z

THRIFT-2642 Recursive structs don't work in python

See https://issues.apache.org/jira/browse/THRIFT-2642.




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


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-05-12 Thread Igor Rogozhin (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16008348#comment-16008348
 ] 

Igor Rogozhin commented on THRIFT-2642:
---

Actualy my team switched to java, but if you need help you can contact with me.
Dont think, that i totaly forget python for 6mo

> 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 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 
> 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.3.15#6346)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-05-12 Thread Jens Geyer (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16008223#comment-16008223
 ] 

Jens Geyer commented on THRIFT-2642:


[~allengeorge], 

I am fine with it as long as 
a) the proposed changes are local to Python stuff (.i.e. there are no changes 
necessary that affect other languages or question the infrastructure in 
general) 
b) if [~lyschoening], [~myTalala], [~econner724] and [~juliengreard] agree with 
your pull request
c) all builds are fine

I can surely do a general review, but my Python expertise is limited, so I 
would not rely on my own opinion alone. Especially not with such a topic. But 
if you 5 guys come to someething you are happy with as a group, we should have 
enough backing to get it merged.  At the end, this is open source.


> 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 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 
> 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.3.15#6346)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-05-10 Thread Allen George (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16005819#comment-16005819
 ] 

Allen George commented on THRIFT-2642:
--

[~jensg] Can I implement the approach discussed above?

> 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 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 
> 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.3.15#6346)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2017-02-07 Thread JIRA

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15856364#comment-15856364
 ] 

Lars Schöning commented on THRIFT-2642:
---

I also just came across this issue. Fbthrift has a straightforward enough fix 
for this. I don't fully understand the IP situation with fbthrift, so maybe 
using their approach is out of the question.

In either case, there are two parts to this problem: 
(1) to solve recursive and cyclic dependencies between structs themselves, (2) 
solve cycles of {{.thrift_spec}}.

The first part is adequately solved by setting {{.thrift_spec}} at the 
bottom of the file.

 {code}
class A(object):
thrift_spec = None

class B(object):
thrift_spec = None

A.thrift_spec = # (...)
B.thrift_spec = # (...)

 {code}

However, since the thrift_spec tuple has the format {{(, 
.thrift_spec)}}, this won't work. There are three approaches now. The 
fbthrift approach is to change {{(, .thrift_spec)}} to a list 
{{\[, None\]}} and fill in the missing bit with a function call.

https://github.com/facebook/fbthrift/blob/3ef868c969464e935b39e336807af1486b2739c3/thrift/lib/py/util/Recursive.py

 A simpler alternative is to make {{thrift_spec}} itself a list and update the 
code like so:

 {code}
class Cyclic(object):
thrift_spec = []


Cyclic.thrift_spec += # [...]

{code}

I don't know what the performance implications are. Iterating over a tuple 
should be slightly faster than iterating over a list, however the fbthrift 
solution also requires accessing lists. Both solutions make {{thrift_spec}} 
mutable.

The third alternative is to change  {{(, .thrift_spec)}}  to 
just {{}}. As far as I can see {{thrift_spec}} is only  used by 
{{TProtocol.readStruct()}}. So the signature of {{TProtocol.readStruct(self, 
obj, thrift_spec, is_immutable=False)}} should be changed to 
{{TProtocol.readStruct(self, obj, is_immutable=False)}} and the access to 
{{thrift_spec}} should be changed to {{obj.thrift_spec}}. As far as I can see, 
{{readStruct()}} is only called from {{TBase.read()}} and 
{{TFrozenBase.read()}}, so this would be a simple change. The method is also 
undocumented. But I don't know how you feel about signature changes. 


> 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 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 
> 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.3.15#6346)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2016-07-21 Thread Igor Rogozhin (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15387504#comment-15387504
 ] 

Igor Rogozhin commented on THRIFT-2642:
---

Hello from 2016.
We still have this problem.

I am using Julien's solution, but this kinda weird.
For full automation it required bash script, that's change this errors.
Maybe someone figure out how we can do it bett

> 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 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 
> 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.3.4#6332)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2015-10-22 Thread Eric Conner (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14970521#comment-14970521
 ] 

Eric Conner commented on THRIFT-2642:
-

The problem is in thrift_spec which is used only by fastbinary.  Right now the 
only option seems to be to manually modify the code as Julien has suggested:
A.thrift_spec = None
for idx in xrange(10):
  A.thrift_spec = (
  1, TType.STRUCT, 'field', (A, A.thrift_spec), None, )
  )

As far as fixing this for fastbinary it gets tricky.  
1) The thrift_spec either needs to move from the class level into a method or 
thrift_spec should be added to the class after it is defined.

2) As written the thrift_spec tuple tries to be self-referential which is not 
really possible in python unless you create lots of inner copies of the tuple.  
It'd work in C with a pointer back to the object since fastbinary is really 
just reading the tuple to see what fields to expect.  It may be possible to 
modify fastbinary to handle this case specifically, but the generated python 
would also need to change as well and its not clear to me how to do that.  
Maybe just using some sentinel value that fastbinary looks for which means "ref 
to my parent".


> 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 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 
> 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.3.4#6332)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2015-07-21 Thread julien greard (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14635740#comment-14635740
 ] 

julien greard commented on THRIFT-2642:
---

Right now, I have a workaround, I have to edit the generated files by hand. 
It's working, but each time I update my objects data structure or create new 
ones, I have to do it. I just need to know if this bugs is major enought 
according to Thrift community's point of view to be fixed soon for my ^next 
developements: I can use recursive data struct if this bug is fixed soon, 
otherwise, I'll find another pattern, no worries ^^

> 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 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 
> 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.3.4#6332)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2015-07-21 Thread Jens Geyer (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14635689#comment-14635689
 ] 

Jens Geyer commented on THRIFT-2642:


[~juliengreard] What do you have so far? 

Any other Pythonians around that could help and/or assist Julien?

> 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 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 
> 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.3.4#6332)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2015-07-21 Thread julien greard (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14635029#comment-14635029
 ] 

julien greard commented on THRIFT-2642:
---

Hello,

Do you know if this bug is planned to be corrected soon ? I haven't been able 
to do any progress on a patch yet, and I probably won't have the time to look 
at it in the next months...

I just need to know if I have to wait for a correction or if I have to get rid 
of the recursivity

> 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 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 
> 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.3.4#6332)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2015-05-13 Thread Jens Geyer (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14542749#comment-14542749
 ] 

Jens Geyer commented on THRIFT-2642:


You will be, just fire away :-) 

Just remember, that you may ask on the mailing lists and/or freenode at any 
time if you get stuck or have questions. Finally, the people who are going to 
review your patch/PR will tell how you did, and help you over the hurdles (if 
there are any at all). 



> 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 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 
> 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.3.4#6332)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2015-05-13 Thread julien greard (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14541728#comment-14541728
 ] 

julien greard commented on THRIFT-2642:
---

Hi,

Thanks for the indication about the formatting,

For the patch, I'll test my solution for a while and I'll look at the python 
generator. But I'm not sure I'll be able to make something clean. 



> 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 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 
> 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.3.4#6332)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2015-05-12 Thread Jens Geyer (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14540703#comment-14540703
 ] 

Jens Geyer commented on THRIFT-2642:


Hi,

there is a "help" icon which lists all the possible formattings. 

Any chance that you coulod create a patch out of your findings and/or 
workaround, or does that make no sense?


> 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 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 
> 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.3.4#6332)


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2015-05-12 Thread julien greard (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14539620#comment-14539620
 ] 

julien greard commented on THRIFT-2642:
---

I did my own work around:
in the example above, I replaced the code:
class Recursive:
thrift_spec = (
None, # 0
(1, TType.LIST, 'Children', (TType.STRUCT,(Recursive, 
Recursive.thrift_spec)), None, ), # 1
)
by
class Recursive:
pass
Recursive.thrift_spec = None
depth = 0
max_depth = 50
while (depth < max_depth):
depth += 1
Recursive. thrift_spec = (
None, # 0
(1, TType.LIST, 'Children', (TType.STRUCT,(Recursive, 
Recursive.thrift_spec)), None, ), # 1
)

Which seems to do the job... It's ugly because I have to edit the generated 
code afterward, but I didn't want to touch at the code generator in Thrift 
code... what do you think ?

> 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:
> {quote}struct Recursive {
> 1: list Children
> }
> {quote}
> Python code:
> {quote}class Recursive:
>   thrift_spec = (
> None, # 0
> (1, TType.LIST, 'Children', (TType.STRUCT,(Recursive, 
> Recursive.thrift_spec)), None, ), # 1
>   )
> {quote}
> An error:
> {quote}Traceback (most recent call last):
>   File "ttypes.py", line 20, in 
> 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
> {quote}



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


[jira] [Commented] (THRIFT-2642) Recursive structs don't work in python

2015-05-12 Thread julien greard (JIRA)

[ 
https://issues.apache.org/jira/browse/THRIFT-2642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14539571#comment-14539571
 ] 

julien greard commented on THRIFT-2642:
---

Hello,

Is there a work around for this bug ? Do you know when it's going to be fixed ?

Thanks


> 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:
> {quote}struct Recursive {
> 1: list Children
> }
> {quote}
> Python code:
> {quote}class Recursive:
>   thrift_spec = (
> None, # 0
> (1, TType.LIST, 'Children', (TType.STRUCT,(Recursive, 
> Recursive.thrift_spec)), None, ), # 1
>   )
> {quote}
> An error:
> {quote}Traceback (most recent call last):
>   File "ttypes.py", line 20, in 
> 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
> {quote}



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