I'm trying to accept a URL-serialized version of the following Python dict using Colander as my validation backend:
{'foo': [1,2,3]}
The way I've approached this was primarily using colander.SequenceSchema in various configurations, none of which produce errors that make much sense:
# first approach
class ListItem(colander.MappingSchema):
item = colander.SchemaNode(colander.Int())
class ListContainer(colander.SequenceSchema):
items = ListItem()
# second approach
class ListContainer(colander.SequenceSchema):
items = colander.SchemaNode(colander.Int())
# third approach
colander.SchemaNode(
colander.Mapping(),
colander.SchemaNode(
colander.Sequence(),
typ=colander.Int(),
name=my_param_name
)
)
I'm actually fairly sure the first two approaches are equivalent.
In terms of actually validating this, I've tried using a number of structures passed to the params kwarg on a requests.get call:
my_param_name = [1,2,3]my_param_name = [(my_param_name, 1), (my_param_name, 2), (my_param_name, 3)]my_param_name = {my_param_name: [1,2,3]}
In every case, Colander will spit out some variation upon my_param_name: u'"1" is not iterable', or in the last case, my_param_name: u'"[1,2,3]" is not iterable'. This error is very obtuse, and the docs don't outline a correct use case for SequenceSchema (or even colander.List) for accepting arrays as values in a URL parameter, and because of Colander's relatively low adoption, it's difficult to find a project on the web which uses either of these in this way.
Is it possible to accept a list of scalar, primitive values as the value of a URL parameter while passing validation using Colander?