Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#187 serializing of a union results in a TypeError

v2.0
closed-fixed
zsi (169)
5
2007-01-02
2006-12-16
Roland Gude
No

The bug was discovered using:
"http://www.pasoa.org/schemas/version024/PStruct.xsd","localPAssertionId"
which is the union of
(u'http://www.w3.org/2001/XMLSchema', u'long'),
(u'http://www.w3.org/2001/XMLSchema', u'string'),
(u'http://www.w3.org/2001/XMLSchema', u'anyURI')

wsdl2py generated theese two classes:
----
class LocalPAssertionId_Def(ZSI.TC.Union, TypeDefinition):
memberTypes = [(u'http://www.w3.org/2001/XMLSchema', u'long'),
(u'http://www.w3.org/2001/XMLSchema', u'string'),
(u'http://www.w3.org/2001/XMLSchema', u'anyURI')]
schema = "http://www.pasoa.org/schemas/version024/PStruct.xsd"
type = (schema, "LocalPAssertionId")
def __init__(self, pname, **kw):
ZSI.TC.Union.__init__(self, pname, **kw)

class localPAssertionId_Dec(ElementDeclaration):
literal = "localPAssertionId"
schema = "http://www.pasoa.org/schemas/version024/PStruct.xsd"
def __init__(self, **kw):
kw["pname"] =
("http://www.pasoa.org/schemas/version024/PStruct.xsd","localPAssertionId")
kw["aname"] = "_localPAssertionId"
if ns3.LocalPAssertionId_Def not in
ns3.localPAssertionId_Dec.__bases__:
bases = list(ns3.localPAssertionId_Dec.__bases__)
bases.insert(0, ns3.LocalPAssertionId_Def)
ns3.localPAssertionId_Dec.__bases__ = tuple(bases)

ns3.LocalPAssertionId_Def.__init__(self, **kw)
if self.pyclass is not None: self.pyclass.__name__ =
"localPAssertionId_Dec_Holder"

----

because there is no factoryMethod for the field localPAssertion in
generated classes which have a field of this type, i tried to assign the
field an integer or string value directly.
obj.set_element_localPAssertion(4711)

However ZSI seems to have big trouble serializing this.
here is what i get from my testcases:

======================================================================
ERROR: testRecordForSuccessRelationship (__main__.ClientTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "provenance/client/test.py", line 56, in
testRecordForSuccessRelationship
keys,response = self.c.record([[utils.createRelationship()]], viewKind,
sink, source)
File "provenance/client/client.py", line 35, in record
response = self.recordBinding.Record(record.toTypeCode())
File
"/home/hafti/workspace/Provenance/src/provenance/serverAPI/ProvenanceService_services.py", line 48, in Record
self.binding.Send(None, None, request,
soapaction="http://www.pasoa.org/schemas/version024/PRecord.xsd", **kw)
File "/home/hafti/ZSI-2.0-rc3/ZSI/client.py", line 224, in Send
sw.serialize(obj, tc)
File "/home/hafti/ZSI-2.0-rc3/ZSI/writer.py", line 117, in serialize
elt = typecode.serialize(self.body, self, pyobj, **kw)
File "/home/hafti/ZSI-2.0-rc3/ZSI/TC.py", line 605, in serialize
pyobj.typecode.serialize(elt, sw, pyobj, **kw)
File "/home/hafti/ZSI-2.0-rc3/ZSI/TCcompound.py", line 273, in serialize
self.cb(elt, sw, pyobj, name=name, **kw)
File "/home/hafti/ZSI-2.0-rc3/ZSI/TCcompound.py", line 403, in cb
what.serialize(elem, sw, v2, **kw)
File "/home/hafti/ZSI-2.0-rc3/ZSI/TCcompound.py", line 273, in serialize
self.cb(elt, sw, pyobj, name=name, **kw)
File "/home/hafti/ZSI-2.0-rc3/ZSI/TCcompound.py", line 403, in cb
what.serialize(elem, sw, v2, **kw)
File "/home/hafti/ZSI-2.0-rc3/ZSI/TCcompound.py", line 273, in serialize
self.cb(elt, sw, pyobj, name=name, **kw)
File "/home/hafti/ZSI-2.0-rc3/ZSI/TCcompound.py", line 422, in cb
what.serialize(elem, sw, v, **kw)
File "/home/hafti/ZSI-2.0-rc3/ZSI/TCcompound.py", line 273, in serialize
self.cb(elt, sw, pyobj, name=name, **kw)
File "/home/hafti/ZSI-2.0-rc3/ZSI/TCcompound.py", line 422, in cb
what.serialize(elem, sw, v, **kw)
File "/home/hafti/ZSI-2.0-rc3/ZSI/TC.py", line 500, in serialize
self.serialize_text_node(el, sw, pyobj)
File "/home/hafti/ZSI-2.0-rc3/ZSI/TC.py", line 452, in
serialize_text_node
text = self.get_formatted_content(pyobj)
File "/home/hafti/ZSI-2.0-rc3/ZSI/TC.py", line 1532, in
get_formatted_content
self.setMemberTypeCodes()
File "/home/hafti/ZSI-2.0-rc3/ZSI/TC.py", line 1487, in
setMemberTypeCodes
typecode = tc.__class__(pname=(self.nspname,self.pname))
TypeError: cannot create 'NoneType' instances

Discussion

  • Roland Gude
    Roland Gude
    2006-12-16

    Logged In: YES
    user_id=1368095
    Originator: YES

    Joshua Boverhof proposed this fix on the Mailinglist:

    $ svn diff TC.py
    Index: TC.py
    ===================================================================
    --- TC.py (revision 1299)
    +++ TC.py (working copy)
    @@ -1482,7 +1482,7 @@
    for nsuri,name in self.__class__.memberTypes:
    tcclass = GTD(nsuri,name)
    if tcclass is None:
    - tc = Any.parsemap.get((nsuri,name))
    + tc = Any.parsemap.get((nsuri,name)) or
    Any.parsemap.get((None, name))
    typecode = tc.__class__(pname=
    (self.nspname,self.pname))
    else:
    typecode = tcclass(pname=(self.nspname,self.pname))

    $ wsdl2py --lazy --address -bu http://www.pasoa.org/schemas/
    version024/ProvenanceService.wsdl
    $ cat > run.py
    #!/usr/bin/env python
    from ProvenanceService_services import *
    typecode = GED("http://www.pasoa.org/schemas/version024/PStruct.xsd",
    "localPAssertionId")
    sw = ZSI.SoapWriter()
    sw.serialize(1234455, typecode)
    print sw

    $ ./run.py
    <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/
    encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ZSI="http://www.zolera.com/schemas/ZSI/" xmlns:xsd="http://
    www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/
    XMLSchema-instance"><SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body
    xmlns:ns1="http://www.pasoa.org/schemas/version024/
    PStruct.xsd"><ns1:localPAssertionId>1234455</ns1:localPAssertionId></
    SOAP-ENV:Body></SOAP-ENV:Envelope>

     
  • Logged In: YES
    user_id=711996
    Originator: NO

    added the patch and also added a unittest, test/test_union.py

    Also discovered need to look for TypeError when sequentially parsing using Union's memberTypes.

     
    • assigned_to: nobody --> boverhof
    • status: open --> pending-fixed
     
  • Logged In: YES
    user_id=1312539
    Originator: NO

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
    • status: pending-fixed --> closed-fixed