flask-openapi3 icon indicating copy to clipboard operation
flask-openapi3 copied to clipboard

Tuples no longer work in query strings

Open jpveooys opened this issue 4 months ago • 0 comments

Environment:

  • Python version: 3.12.3
  • Operating system: Ubuntu 24.04
  • Flask version: 3.0.3
  • flask-openapi3 version: 4.0.0

Similar to #182, this also regressed in 2f33e859b9fa8a6b0114b0ae850cb4b1fda1e4c6.

Example:

class TupleModel(BaseModel):
    values: tuple[int, int]

@app.get("/tuple-test")
def tuple_test(query: TupleModel):
    assert query.values == (2, 2)
    return b"", 200


def test_tuple_query(client):
    resp = client.get(
        "/tuple-test",
        query_string={"values": [2, 2]},
    )
    assert resp.status_code == 200, resp.json

The error returned is:

{
    "code": "400",
    "message": '[{"type":"tuple_type","loc":["values"],"msg":"Input should be a '
    "valid "
    'tuple","input":"2","url":"https://errors.pydantic.dev/2.8/v/tuple_type"}]',
    "more_info": [
        {
            "line": 1,
            "location": "GenericError.py",
            "message": "400:Bad Request",
            "method": "GenericError",
        }
    ],
}

It is only using the first value from the query string.

The generated OpenAPI schema still looks okay. There is also no problem using a list instead of a tuple.

jpveooys avatar Oct 01 '24 14:10 jpveooys