mvantellingen / python-zeep

A Python SOAP client
http://docs.python-zeep.org
Other
1.87k stars 579 forks source link

Bug in validation of xsd:sequence within xsd:choice #1345

Open pjuvigny-oef opened 1 year ago

pjuvigny-oef commented 1 year ago

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 :/.

yeramirez commented 1 year ago

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

pjuvigny-oef commented 1 year ago

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.