Client can't validate an answer from spyne SOAP server due to whitespaces

376 Views Asked by At

I have Django model

class OrderItem(models.Model):
    comment = models.CharField('comment', max_length=255, blank=True)
    ..... 

and other fields which are not important.

And I have spyne models described like this

class OrderItemModel(DjangoComplexModel):
    __type_name__ = 'OrderItem'

    class Attributes(DjangoComplexModel.Attributes):
        django_model = OrderItem

and function which generate the response

@rpc(Int, _returns=Iterable(OrderItemModel)) 
def GetOrderItems(self, id):
     order = get_object(Order, pk=id)
     items = order.objects.all()
     return items

xml description is

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
       <SaveOrderItem xmlns="app.sync">
        <model>
           <comment xmlns="app.sync.models">[normalizedString]</comment>
        </model>
       </SaveOrderItem>
        </Body>
</Envelope>

The server which make request then validate response, and raise an exception when found that comment have spaces on start or end os string. As I understand the type normalizedString does not allow to use not stripped stings. So is any way to remove spaces on the fly from that type of strings. I looked in to the source and find class definition

class NormalizedString(Unicode):
    __type_name__ = 'normalizedString'
    __extends__ = Unicode

    class Attributes(Unicode.Attributes):
        white_space = "replace"

So that white_space = "replace" do that check on the client side.

1

There are 1 best solutions below

0
On

I have found solution for this issue: I just replace 'CharField' in the default field mapper to Unicode by the one line

default_model_mapper.register('CharField', primitive.Unicode) instead of default ('CharField', primitive.NormalizedString)

which is described in spyne/util/django.py