arskom / spyne

A transport agnostic sync/async RPC library that focuses on exposing services with a well-defined API using popular protocols.
http://spyne.io
Other
1.13k stars 313 forks source link

The service returns different responses to the same request, in no particular order. #650

Closed random343 closed 3 years ago

random343 commented 3 years ago

The service returns different responses to the same request, in no particular order.

Example service:

# -*- coding: utf-8 -*-

from spyne import Application, rpc, ServiceBase
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from spyne.model.primitive import String
from spyne.model.complex import ComplexModel

class ErrorType(ComplexModel):

    __namespace__ = "other.ns"

    errorCode = String.customize(sub_ns="other.ns")

class PortType(ServiceBase):

    @rpc(_returns = [ErrorType.customize()])
    def test(ctx):
        return ErrorType(errorCode="code")

app = Application([PortType], tns="target.ns", in_protocol=Soap11(validator="soft"), out_protocol=Soap11())
application=WsgiApplication(app)

Request:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <test xmlns="target.ns"/>
    </Body>
</Envelope>

Response:

<?xml version="1.0" encoding="UTF-8"?>
<soap11env:Envelope xmlns:s0="other.ns" xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="target.ns">
    <soap11env:Body>
        <tns:testResponse>
            <tns:testResult0>
                <s0:errorCode>code</s0:errorCode>
            </tns:testResult0>
        </tns:testResponse>
    </soap11env:Body>
</soap11env:Envelope>

or

<?xml version="1.0" encoding="UTF-8"?>
<soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="target.ns">
    <soap11env:Body>
        <tns:testResponse>
            <tns:testResult0>
                <ns0:errorCode xmlns:ns0="other.ns">code</ns0:errorCode>
            </tns:testResult0>
        </tns:testResponse>
    </soap11env:Body>
</soap11env:Envelope>

Why is that? How to avoid this?

plq commented 3 years ago

Can you add the missing bits and fix the formatting as well?

plq commented 3 years ago

Both xml documents are equivalent, so any SOAP client should properly parse both documents.

That said, I can't see how the same server could produce different outputs randomly like this. Are you sure nothing is different between the servers that produce these two responses?

random343 commented 3 years ago

I understand that the answers are equivalent. But I met a client for whom these are different answers.

I noticed a feature. This situation is reproduced only when the script is run through an external uwsgi server. Through the built-in from wsgiref.simple_server import make_server it does not repeat itself.

plq commented 3 years ago

this is outside of scope of this project. xml canonicalization should be made in an after_serialize hook