Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OperationProxy return types #1425

Open
atatarn opened this issue Aug 7, 2024 · 1 comment
Open

OperationProxy return types #1425

atatarn opened this issue Aug 7, 2024 · 1 comment

Comments

@atatarn
Copy link

atatarn commented Aug 7, 2024

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
Copy link
Author

atatarn commented Aug 10, 2024

To be more specific:

# Check if we can remove the wrapping object to make the return value
# easier to use.
result = next(iter(result.__values__.values()))
if isinstance(result, xsd.CompoundValue):
children = result._xsd_type.elements
attributes = result._xsd_type.attributes
if len(children) == 1 and len(attributes) == 0:
item_name, item_element = children[0]
retval = getattr(result, item_name)
return retval
return result

"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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant