[Fedora-suds-list] Array of complex type weirdness

Martin Aspeli optilude at gmail.com
Thu Jul 1 00:20:55 UTC 2010


On 1 July 2010 03:36, Matt C <mcauthorn at gmail.com> wrote:
> On the surface this looks fine: the Suds response object contains the
> transactions attribute, inside of which is an array of Transaction[]
> objects, each with purchase date, cost, and status attributes.

Except that when we use the Java server (which at least is trying to
do the same thing) the 'transactions' attribute is a Python list,
which contain a Transaction object.

With the soaplib server, we get an intermediate "holder" object that
has a single attribute "Transaction" (the type name of the array),
which in turn contains that Python list. The extra level of
indirection is a bit frustrating, not at least because it means our
client code needs special casing for the mock server.

My expectation was that Suds would just "unwrap" this so that the
'transactions' attribute would always be a list.

Cheers,
Martin

> On Tue, Jun 22, 2010 at 2:56 AM, Martin Aspeli <optilude at gmail.com> wrote:
>> Hi,
>>
>> I have a soaplib server (emulating a Java server) which does this:
>>
>> from soaplib.serializers.primitive import String, Integer, DateTime,
>> Array, Fault
>> from soaplib.serializers.clazz import ClassSerializer
>>
>> from soaplib.service import SoapServiceBase
>> from soaplib.service import soapmethod
>>
>> class Transaction(ClassSerializer):
>>
>>    class types:
>>        cost = Integer
>>        purchaseDate = DateTime
>>        status = Integer
>>
>> class HistoryResponse(ClassSerializer):
>>
>>    class types:
>>        transactions = Array(Transaction)
>>        totalRecords = Integer
>>
>>
>> class TransactionService(SoapServiceBase):
>>
>>    @soapmethod(String, Integer, DateTime, DateTime, Integer,
>> _returns=HistoryResponse)
>>    def getHistory(self, tokenId, status, dateFrom, dateTo, pageId):
>>
>>        transactionsList = createAPythonListOfTransactionObjects()
>>        response = HistoryResponse()
>>        response.transactions = transactionsList
>>        response.totalRecords = 1000
>>
>> In Suds (in another process), when I get back the results from calling
>> getHistory(), the return value prints like this:
>>
>> (HistoryResponse){
>>   totalRecords = 1000
>>   transactions =
>>      (TransactionArray){
>>         _type = "tns:TransactionArray"
>>         Transaction[] =
>>            (Transaction){
>>               purchaseDate = 2010-02-28 12:00:00
>>               cost = 1500
>>               status = 8
>>            },
>>            (Transaction){
>>               purchaseDate = 2010-02-28 12:00:00
>>               cost = 1200
>>               status = 2
>>            },
>>      }
>>  }
>>
>>
>> To loop over transactions, I have to do:
>>
>> for item in response.transactions.Transaction:
>>    ...
>>
>> Which is pretty awkward. I also suspect that this may not always be
>> necessary, as we had some other mocks going with SoapUI where it was
>> sufficient to iterate over response.transactions directly.
>>
>> Am I doing something wrong?
>>
>> Cheers,
>> Martin
>> _______________________________________________
>> suds mailing list
>> suds at lists.fedoraproject.org
>> https://admin.fedoraproject.org/mailman/listinfo/suds
>>
>


More information about the suds mailing list