[spyne] Spyne and complex model tree structures

Burak Arslan burak.arslan at arskom.com.tr
Thu Jul 7 20:49:08 UTC 2016

On 07/05/16 16:19, Marduk wrote:
> But it's impossible to declare Array(TreeNode) from inside TreeNode
> because TreeNode isn't visible from it self. So is it possible to
> somehow declare this complex type and send it to spyne?

Yes, two ways:

1. Use SelfReference. ie

    class TreeNode(ComplexModel):
        children = Array(SelfReference)

    See the testcases:

2. Use append_field or insert_field. ie

    class TreeNode(ComplexModel):
        i = Integer

    TreeNode.append_field('children', TreeNode)

Beware that Spyne can only serialize DAGs (DAG == directed acyclic
graph) without any efforts towards breaking cycles. In other words, if
an object somehow ends up referring to itself, only recursion error will
terminate serialization. (Trees are DAGs so you should be fine here)

Among the supported protocols, only SOAP supports serializing cyclic
graphs (via references, see
https://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383520) but it's
not implemented. Patches are welcome!

One exception, log_repr, breaks cycles by serializing objects only once.
Other occurrences are serialized as only a simple ellipsis.

Best regards,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spyne.io/archives/people/attachments/20160707/1ae20a02/attachment.html>

More information about the people mailing list