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

Support integer values in maxOccurs attribute #169

Merged
merged 1 commit into from Jul 28, 2018

Conversation

Projects
None yet
2 participants
@rhertzog
Copy link
Contributor

rhertzog commented Jul 18, 2018

With the following complex type:

<element name="selectedContractList" nillable="true" type="tns1:selectedContractList"/>
[...]
<complexType name="selectedContractList">
    <sequence>
	<element maxOccurs="25" minOccurs="1" name="selectedContract" type="xsd:string"/>
    </sequence>
</complexType>

pysimplesoap would generate the following key in the services description:

selectedContractList: selectedContractList

This does not allow the input of multiple values in any way. I was expecting to
be able to pass this:

'selectedContractList': [ {'selectedContract': '...'}, … ]

But this would result in "TypeError: unhashable type: 'dict'" in the
wsdl_validate_params() method. See full traceback below.

With this patch, I'm now able to pass the desired structure.

Full traceback of the unexpected error:

ERROR: test_do_web_payment (__main__.WebPaymentAPITestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "pypayline/tests-soap-services.py", line 101, in test_do_web_payment
    cancel_url='http://freexian.com/cancel/',
  File "/home/rhertzog/freexian/projets/boutique/python-payline/pypayline/client.py", line 220, in do_web_payment
    notificationURL=notification_url
  File "/home/rhertzog/freexian/projets/boutique/python-payline/pypayline/backends/soap.py", line 38, in doWebPayment
    response = self.soap_client.doWebPayment(**data)
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 177, in <lambda>
    return lambda *args, **kwargs: self.wsdl_call(attr, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 351, in wsdl_call
    return self.wsdl_call_with_args(method, args, kwargs)
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 372, in wsdl_call_with_args
    method, params = self.wsdl_call_get_params(method, input, args, kwargs)
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 404, in wsdl_call_get_params
    valid, errors, warnings = self.wsdl_validate_params(input, all_args)
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 474, in wsdl_validate_params
    next_valid, next_errors, next_warnings = self.wsdl_validate_params(struct[key], value[key])
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 474, in wsdl_validate_params
    next_valid, next_errors, next_warnings = self.wsdl_validate_params(struct[key], value[key])
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 470, in wsdl_validate_params
    if key not in struct:
TypeError: unhashable type: 'dict'
Support integer values in maxOccurs attribute
With the following complex type:
```
<element name="selectedContractList" nillable="true" type="tns1:selectedContractList"/>
[...]
<complexType name="selectedContractList">
    <sequence>
	<element maxOccurs="25" minOccurs="1" name="selectedContract" type="xsd:string"/>
    </sequence>
</complexType>
```

pysimplesoap would generate the following key in the services description:
```
selectedContractList: selectedContractList
```

This does not allow the input of multiple values in any way. I was expecting to
be able to pass this:
```
'selectedContractList': [ {'selectedContract': '...'}, … ]
```

But this would result in "TypeError: unhashable type: 'dict'" in the
wsdl_validate_params() method. See full traceback below.

With this patch, I'm now able to pass the desired structure.

Full traceback of the unexpected error:
```
ERROR: test_do_web_payment (__main__.WebPaymentAPITestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "pypayline/tests-soap-services.py", line 101, in test_do_web_payment
    cancel_url='http://freexian.com/cancel/',
  File "/home/rhertzog/freexian/projets/boutique/python-payline/pypayline/client.py", line 220, in do_web_payment
    notificationURL=notification_url
  File "/home/rhertzog/freexian/projets/boutique/python-payline/pypayline/backends/soap.py", line 38, in doWebPayment
    response = self.soap_client.doWebPayment(**data)
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 177, in <lambda>
    return lambda *args, **kwargs: self.wsdl_call(attr, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 351, in wsdl_call
    return self.wsdl_call_with_args(method, args, kwargs)
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 372, in wsdl_call_with_args
    method, params = self.wsdl_call_get_params(method, input, args, kwargs)
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 404, in wsdl_call_get_params
    valid, errors, warnings = self.wsdl_validate_params(input, all_args)
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 474, in wsdl_validate_params
    next_valid, next_errors, next_warnings = self.wsdl_validate_params(struct[key], value[key])
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 474, in wsdl_validate_params
    next_valid, next_errors, next_warnings = self.wsdl_validate_params(struct[key], value[key])
  File "/usr/lib/python2.7/dist-packages/pysimplesoap/client.py", line 470, in wsdl_validate_params
    if key not in struct:
TypeError: unhashable type: 'dict'
```

@reingart reingart merged commit 033e589 into pysimplesoap:master Jul 28, 2018

@reingart

This comment has been minimized.

Copy link
Member

reingart commented Jul 28, 2018

Great, thanks!

As maxOccurs could be an integer or "unbounded", this patch seems safe according the standards: https://www.w3.org/TR/xmlschema-0/#OccurrenceConstraints

I wonder when the or 0 conditional expression part will be used, as an empty string doesn't seem a valid value (but it could be None if the tag doesn't have that attribute, IIRC).
Maybe the default should be 1, but this looks like a minor detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.