Skip to content

In docs, DelimitedList field doesn't produce the expected query parameter format  #416

@pamelafox

Description

@pamelafox

I am using the DelimitedList field like so:

class PieChartParams(Schema):
    title = String(required=False, validate=Length(0, 30))
    values = DelimitedList(Number(validate=Range(min=0, max=3.4028235e38)), required=True)
    labels = DelimitedList(String)

And I am using it for the query parameters:

@app.get("/charts/pie")
@app.input(PieChartParams, location="query")
@app.output(ImageOutSchema, content_type='image/png')
def pie_chart(data: dict):
    fig = Figure()
    axes: Axes = fig.add_subplot()
    axes.pie(data["values"], labels=data.get("labels"))
    axes.set_title(data.get("title"))
    return send_figure_as_png(fig)

That field lets me send a query like so:

charts/pie?title=Enrolled%20students&labels=C,Ruby,Java,Python&values=10,20,15,30.5

However, if I enable the APIFlask docs and add multiple values to the DelimitedList fields, the generated URL is instead like this:

charts/pie?title=Enrolled%2520students&values=10&values=20&values=30&values=15&labels=C&labels=Ruby&labels=Java&labels=Python

That query parameter is repeating the fields instead of putting them as comma separated values. That isn't what the parser expects, apparently, as the values and labels come in to APIFlask as lists with single values (the first of each parameter).

For full code, see:
https://github.com/pamelafox/flask-charts-api-container-app/blob/main/src/api/__init__.py

Environment:

  • Python version: 3.11
  • Flask version: 2.2.3
  • APIFlask version: 1.3.0

Docs screenshot here:
Screenshot of APIFlask docs for DelimitedList field

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions