[spyne] Complex data types and inheritance

Alex ralienpp at gmail.com
Fri Jun 6 10:13:49 UTC 2014


I have a hierarchy of data types that I built with the intention to
avoid duplication of code and effort. For example, there is a basic
data type defined as such:

class RequestSigned(ComplexModel):
   identifier = Uuid
   signature = Unicode

And a few others that contain their own data, besides the `identifier`
and `signature`, ex:

class FooBar(RequestSigned):
   foo = Unicode
   bar = Uuid

The data are exchanged via JSON strings, on top of HTTP. When a
spynified function of the server returns an object of the FooBar
class, I do something like this

result = FooBar()
result.identifier = xxxxxxxxx
result.signature = yyyyyyyyyyy
result.foo = zzzzzz
result.identifier = qqqqqqqqqqq
return result

The assignments go without an error, but the client only gets `foo`
and `bar` in the returned object, not the other attributes, which I
assumed would be there.

So it seems that one of my basic assumptions was wrong - such form of
inheritance does not work; perhaps I was fooled by the fact that no
errors were thrown when I sent a test request to the server (and did
not bother to examine the result carefully).

What is the recommended method of reusing data types? I have a large
hierarchy of types and it would be a pity if I had to explicitly
declare everything in each class. Perhaps I am missing something?


More information about the people mailing list