[spyne] String constraints and enums

Alex ralienpp at gmail.com
Tue Jun 17 16:35:48 UTC 2014


Thank you for the reply and the clarifications.

> The example you sent doesn't have anything to do with the code path
> you're following here. Could you provide a working example for this case
> as well?
Now I understand why, these are indeed different issues, but they have
something in common - me (-:

I was getting the input data from a colleague and processing it in an
application, which uses an Array for one of the data types.

I overlooked the fact that in that particular structure, he was giving
me a string, rather than an array of strings. Spyne expected an Array,
so that is why it was iterating over the sequence.

The sequence was a string, so Spyne iterated over each of its
characters; when it said "wrong value `n`"; I assumed it meant "wrong
value `new`" but didn't express that properly, but it really meant `n`
and it knew what it was saying (-:



When I built a minimalistic example to replicate that behaviour, I got
my sample input from the same colleague - so the problem propagated
into the test too.

That's embarrassing, I must admit. Having concentrated on it so much I
began examining minute details and debugging it in pdb, instead of
paying closer attention to the input data. Since it is all in one line
and unindented - spotting that extra pair of { } or quotes is tricky.


It would have been better if Spyne told me "I expected an Array, but
you gave me a String", hinting that validation failed not because the
value was wrong, but because of a type mismatch.

Would that be possible to enforce that? After all, a JSON
representation is different for lists and strings:
`"status" : ["new", "anotherStatus"]` vs `"status" : "new"`



I will double-check these conclusions and confirm that this is
resolved. Thank you for your intervention.


More information about the people mailing list