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

Empty array/list parses as None #923

Open
apexo opened this issue Feb 28, 2019 · 3 comments
Open

Empty array/list parses as None #923

apexo opened this issue Feb 28, 2019 · 3 comments

Comments

@apexo
Copy link

apexo commented Feb 28, 2019

  1. zeep version 3.2.0
  2. WSDL: https://gist.github.com/apexo/f1ffbbb37764032bebb1936c3e8e8c25
  3. Script: https://gist.github.com/apexo/372f69deee0a132458d506e78e8bea3d

So I have a WSDL with a request that contains an optional repeatable element <list-entry> (minOccurs=0, maxOccours=unbounded) that is wrapped in another element (<list-wrapper>) .

The sample script parses this document:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
    <testRequest>
      <list-wrapper>
        <list-entry>1</list-entry>
      </list-wrapper>
    </testRequest>
  </env:Body>
</env:Envelope> 

as follows (kind of expected):

{
    'list-wrapper': {
        'list-entry': [
            '1'
        ]
    },
    'dummy': None
}

while

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
    <testRequest>
      <list-wrapper>
      </list-wrapper>
    </testRequest>
  </env:Body>
</env:Envelope> 

is parsed as

{
    'list-wrapper': None,
    'dummy': None
}

I find this a bit surprising. IMO, the latter should parse as

{
    'list-wrapper': {
        'list-entry': []
    },
    'dummy': None
}

Otherwise it is impossible to tell whether <list-wrapper> itself was present in the request or not (if <list-wrapper> were optional in the WSDL which it is not in the reduced sample). But whether the wrapper is present or not sometimes makes a semantic difference. And that's my problem. Thank you for your attention.

@apexo
Copy link
Author

apexo commented Feb 28, 2019

If I comment out lines 160-161 in xsd/types/complex.py

            #if allow_none and len(elements) == 0 and len(attributes) == 0:
            #    return

it works as expected.

@apexo
Copy link
Author

apexo commented Feb 28, 2019

This change breaks 3 test cases:

  • test_any_optional
  • test_build_sequence_with_optional_elements
  • test_nested_complex_type_optional

For test_any_optional, I can't really tell what the expected behaviour could be.

For test_build_sequence_with_optional_elements, I'd say: works as expected if we want the wrapper element (item_2) to be significant. Also I think the test case is wrong, item_2 shouldn't be empty. AFAIK, xsi:nillable="true" doesn't imply minOccurs=0.

For test_nested_complex_type_optional, kind of the same as test_build_sequence_with_optional_elements. Also: item_2 itself shouldn't be empty? It should contain a sequence of elements, of which at least one (item_2b) is not optional.

@martinlehoux
Copy link

I have the same issue, I will try you solution @apexo

martinlehoux added a commit to GreenGoTech/python-zeep that referenced this issue Oct 2, 2024
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

2 participants