fastapi: FastAPI 0.68.0 Breaks Usage of tuple in Input / Output compared to 0.67.0
First Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
# main.py
import uvicorn
from fastapi import FastAPI, Form
app = FastAPI()
@app.post("/")
def hello(arg: tuple[int, int] = Form(...)) -> str:
pass
if __name__ == "__main__":
uvicorn.run("main:app", port=8080)
Description
- Run
pip install uvicorn fastapi==0.68.0. - Run
python ./main.py - Hit
localhost:8080/docs, observe internal server error with below validation errors:
pydantic.error_wrappers.ValidationError: 2 validation errors for OpenAPI
components -> schemas -> Body_hello__post -> properties -> arg -> items
value is not a valid dict (type=type_error.dict)
components -> schemas -> Body_hello__post -> $ref
field required (type=value_error.missing)
- Run
pip install fastapi==0.67.0 - Hit
localhost:8080/docs, observe that endpoint documentation is successfully generated.
Operating System
Linux
Operating System Details
Ubuntu 20.04
FastAPI Version
0.68.0 has bug, 0.67.0 does not have bug.
Python Version
3.9
Additional Context
Any use of tuple in an input (Form, and BaseModel as JSON) or output (BaseModel as JSON) results in above error.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 16
- Comments: 17 (4 by maintainers)
Commits related to this issue
- Fix OpenAPI docs not rendering There is a regression bug in FastAPI/Pydantic (see https://github.com/tiangolo/fastapi/issues/3665) that prevents the OpenAPI interactive documentation to render when w... — committed to davelopez/galaxy by davelopez 3 years ago
- downgrade fastapi to <v0.68 to avoid tiangolo/fastapi#3665 — committed to wri/gfw-data-api by solomon-negusse 3 years ago
- Merge pull request #264 from wri/hotfix/downgrade-fastapi downgrade fastapi to <v0.68 to avoid tiangolo/fastapi#3665 — committed to wri/gfw-data-api by solomon-negusse 3 years ago
According to this: https://stackoverflow.com/questions/57464633/how-to-define-a-json-array-with-concrete-item-definition-for-every-index-i-e-a it’s possible to have tuples in openapi3.1.
It could be great if @tiangolo could tell us if FastAPI will support Tuples again or if we need adapt our APIs. For now we are stuck in 0.67
Thanks for the discussion everyone! This should be solved by https://github.com/tiangolo/fastapi/pull/3874
It is available in FastAPI
0.73.0, released in the next hours. 🎉For more context, check the last comment there: https://github.com/tiangolo/fastapi/pull/3874#issuecomment-1019578028
In short, using tuples now won’t break the rest of Swagger UI.
And although they are supported by OpenAPI 3.1.0, Swagger UI doesn’t support OpenAPI 3.1.0 yet. Even though FastAPI already has a couple of corner cases where it is more compatible with 3.1.0, I can’t change the generated version yet, as Swagger UI wouldn’t render it at all.
So, you can continue using tuples with FastAPI
0.73.0, those tuples won’t always be properly rendered in Swagger UI (as they have never been), but now that won’t break the rest of Swagger UI, and you will get the proper validation, etc. 🎉Is there any way to get @tiangolo 's attention on this issue? There are now at least 4 dupes of this issue (#3686, #3782, #3898, and #4168), and 2 open PRs (#3874 & #4169), each with exactly the same 1-line fix which works perfectly. We’re all (anyone using tuples) stuck on version 0.67.0 until something is done…
I use
typing.Tuplefor geolocation.This seems a legit use of tuple, no?
I understand your frustration, I am also waiting for this to be fixed. However, I don’t think your claim of FastAPI being unmaintained is true at all.
For better or for worse, FastAPI is a project that stands on the shoulders of several other projects. Advocating for changes and improvements in those projects takes time. See this comment: https://news.ycombinator.com/item?id=29484907
@elrik75 I have the same thought. Look at the merged PR, most recent PR is doc translations and update dependencies.
Here https://github.com/tiangolo/fastapi/issues/1507#issuecomment-640240477 is the answer of this, but I don’t think that’s is a good solution.
Patching with some workaround(like this PR) is better than waitting for support with bug
Same as it did in 0.67.0, the generated endpoint docs look like this: