[spyne] String constraints and enums

Alex ralienpp at gmail.com
Tue Jun 17 12:27:31 UTC 2014

I'm sorry, I accidentally sent the previous message without finishing it.


I'm struggling with the following situation. There's a data type
defined as follows:

RequestStatus = Unicode(values=['new', 'processed'])

When I send a request, Spyne (the latest version from the git repo)
returns the following error:
ValidationError: Fault(Client.ValidationError: 'The value "u\'n\'"
could not be validated.')

Since `n` is not in my request, I assumed it is incorrectly handling
`new`, or that I did not define it correctly.

This brought me to some inconsistencies in the manual. On one hand,
the definition is using a tuple, rather than a list, ex:
`application = Unicode(values=('usermgr', 'accountmgr'))`

This is a reference:

On the other hand, the constraints are given as a list:
`SomeUnicode = Unicode(values=['x', 'y', 'z'])`

The source of this notation is:

I tried them both and I got the same behaviour.  I then tried to use
the Enum type, as such:
`RequestStatus = Enum('new', 'procesed', type_name='RequestStatus')`

And Spyne gave me the same error.

So, the questions are:
1. what is the difference between these notations (if they are both acceptable)
2. why is it not working? (incorrect use, or an issue in the implementation?)

I've tried to debug it myself and what I find weird is this part in
spyne/protocol/dictdoc.py, inside _doc_to_object:

#at this point `doc` is "new"
if issubclass(class_, Array):
     for child in doc:
child, validator))

Spyne gets inside the loop and iterates over the string, applying some
procedure to each of its characters, the first one is `n`, it doesn't
match the given constraint, so an error is shown.

I've changed that part to
        if issubclass(class_, Array):
            retval = [ ]
            (serializer,) = class_._type_info.values()

            #if doc == 'new': pdb.set_trace()
            if unicode == type(doc):

   #return doc
                retval.append(self._from_dict_value(serializer, doc, validator))
                for child in doc:
                    retval.append(self._from_dict_value(serializer, child,

            return retval

Well, in this case no validation errors are thrown, but Spyne returns
an empty string to the client, which is not what I expected.

I will put together a minimalistic sample that demonstrates this error
and send it in a follow-up email.


More information about the people mailing list