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

Bug in validation of xsd:sequence within xsd:choice

Open pjuvigny-oef opened this issue 3 years ago • 2 comments

Hi, the XSD validation seems to fail on sequence within choice, when deserializing a webservice response (zeep 4.1.0).

The XSD:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="test" type="Test"/>
  <xsd:complexType name="Test">
    <xsd:choice>
        <xsd:sequence>
            <xsd:element name="choice1_seq1"/>
            <xsd:element name="choice1_seq2" minOccurs="0"/>
        </xsd:sequence>
        <xsd:element name="choice2"/>
    </xsd:choice>
  </xsd:complexType>
</xsd:schema>

First problem: With a response that only have choice2:

<test>
   <choice2/>
</test>

I've got a error saying Unexpected element 'choice2', expected 'choice1_seq1'

Second problem:

<test>
</test>

Validates (it should throw Element 'test': Missing child element(s). Expected is one of ( choice1_seq1, choice2 ).)

Sorry for the lack of testable script :/.

pjuvigny-oef avatar Oct 10 '22 16:10 pjuvigny-oef

What code are you using, according to the error you are not passing the correct parameters, these are in wsdl.

yeramirez avatar Dec 26 '22 22:12 yeramirez

Something like:

client = zeep.Client(os.path.join(os.path.dirname(__file__), "wsdl", self.wsdl_path))
service = client.create_service(self.method_binding, self.endpoint_url)
service.operation(...)

The real life problem is coming from a validation failing on a perfectly fine WSDL response from the server (the SOAP endpoint is provided by a state company, highly used and tested).

The workaround is off course to add:

zeep_settings = zeep.Settings(strict=False)

But I would rather not.

pjuvigny-oef avatar Jan 02 '23 09:01 pjuvigny-oef