I am using webargs to parse parameters from request.args
with Marshmallow and pass them as arguments to a Flask view. My client uses a comma separated list to represent multiple values for a key:
/queues/generate?queue_id=4&include_ids=1,2,3
To parse this I use Marshmallow's DelimitedList
field.
from marshmallow import Schema, fields
from webargs import use_args
from webargs.fields import DelimitedList
class GenerationParamsSchema(Schema):
queue_id = fields.Integer(required=True)
include_ids = DelimitedList(fields.Integer(), required=False)
@queues.route('/generate_content', methods=['GET'])
@use_args(GenerationParamsSchema(strict=True))
def generate_content_count(generation_params):
...
However, if I generate the URL with Flask's url_for
, it produces duplicate keys for each value:
url_for('queues.generate', queue_id=4, include_ids=[1, 2, 3])
/queues/generate?queue_id=4&include_ids=1&include_ids=2&include_ids=3
Parsing this with a DelimitedList
field only captures the first value. Changing to a List
field correctly captures the values again. So either my Flask URLs fail, or my client URLs fail.
I can't change how my client generates URLs, so I'd like to stick with parsing using the DelimitedField
. How can I make url_for
generate the same style?