Hi Jeff,
On 7 May 2010 00:32, Jeff Ortel <jortel(a)redhat.com> wrote:
>> An /empty/ (nil) element<middleName
xsi:nil="1"/> contained in the
>> document
>> is represented in the unmarshalled object as an attribute with a value =
>> None. But, this element must be defined in the xsd as<xs:element
>> xs:nillable="1"/>.
>
> Okay. I suspect our WSDL doesn't do this. Maybe it should.
>
>> An /empty/ (non-nil) element<middleName/> contained in the document is
>> represented in the unmarshalled object as an attribute with a value =
''.
>> None (nil) must be represented in the document with xsi:nil="1".
>
> That's actually seems entirely wrong to me. The WSDL has specified a
> type for this attribute. In the example below, the attribute is of a
> type 'address', another complex type. For that to be a string is just
> plain wrong, and makes for some pretty awkward duck typing.
Sorry, I should have been more specific here. We were talking about
<middleName/> which is an xs:string. Only empty xs:string elements are
interpreted as ''. All other types such as (int, bool, custom, ..) which
cannot by definition be ('') - will be interpreted as (None) unless a
default is specified in the XSD.
Ok, that may be a bug then (or more weirdness in the WSDL). We have an
element like <address /> in the response and it's coming back as "".
When it's set (so we get
<address><street>...</street>...</address>),
it comes back as the correct complex data structure.
This is uglier but safer:
key = 'middlename'
if key in response:
session[key] = response[key]
else:
session[key] = None
Ah, I didn't realise it supported __getitem__ as well as __getattr__.
Does it also support .get()?
Cheers,
Martin