python-zeep icon indicating copy to clipboard operation
python-zeep copied to clipboard

OperationProxy return types

Open atatarn opened this issue 1 year ago • 1 comments

It seems like the OperationProxy might return zeep.xsd.valueobjects.CompoundValue or lxml.etree.Element.

This is an excerpt from WSDL file, this Response is returned as CompundValue:

      <s:element name="LogonResponse">
        <s:complexType>
          <s:sequence>
            <s:element maxOccurs="1" minOccurs="1" name="pstrSessionToken" type="s:string" />
            <s:element maxOccurs="1" minOccurs="1" name="pSessionInfo" type="tns:Element" />
            <s:element maxOccurs="1" minOccurs="1" name="pstrSecurityToken" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>

But in this case an Element is returned:

<s:element name="ExecuteQueryResponse">
    <s:complexType>
        <s:sequence>
            <s:element maxOccurs="1" minOccurs="1" name="pdomOutput" type="tns:Element" />
        </s:sequence>
    </s:complexType>
</s:element>

This leads to confusions as to how to treat the returned values and triggers mypy alerts. Is it possible to somehow instrument the OperationProxy to always return e.g. CompundValue that could be unpacked manually later on if needed?

atatarn avatar Aug 07 '24 10:08 atatarn

To be more specific: https://github.com/mvantellingen/python-zeep/blob/377d9313b1b4807a31a5ee42227f1dc7e7e0471e/src/zeep/wsdl/messages/soap.py#L126-L136

"to make the return value easier to use" in this particular case makes things more different for the client:

  • client code has to know which attributes should be passed when calling zeep.proxy.OperationProxy. This knowledge could be obtained from the WSDL definition.
  • as a return value client code will receive either etree.Element or zeep.xsd.valueobjects.CompundValue

Seems fair enough to always return zeep.xsd.valueobjects.CompundValue so that the client will have to use its properties using the same WSDL definition as a source of truth about the response structure.

atatarn avatar Aug 10 '24 11:08 atatarn