Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastAPI 0.68.0 Breaks Usage of tuple in Input / Output compared to 0.67.0 #3665

Closed
9 tasks done
MarioIshac opened this issue Aug 7, 2021 · 17 comments
Closed
9 tasks done

Comments

@MarioIshac
Copy link

MarioIshac commented Aug 7, 2021

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

  1. Run pip install uvicorn fastapi==0.68.0.
  2. Run python ./main.py
  3. 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)
  1. Run pip install fastapi==0.67.0
  2. 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.

@MarioIshac MarioIshac added the question Question or problem label Aug 7, 2021
@MarioIshac MarioIshac changed the title FastAPI 0.68 Breaks Usage of tuple in Input / Output compared to 0.67.0 FastAPI 0.68.0 Breaks Usage of tuple in Input / Output compared to 0.67.0 Aug 7, 2021
@Mause
Copy link
Contributor

Mause commented Aug 8, 2021

What are you expecting a tuple in a form field to look like?

@MarioIshac
Copy link
Author

What are you expecting a tuple in a form field to look like?

Same as it did in 0.67.0, the generated endpoint docs look like this:

TupleAsFormBody

@elrik75
Copy link

elrik75 commented Aug 9, 2021

I use typing.Tuple for geolocation.

class Model(BaseModel):
    name: str
    location: Tuple[float, float]

This seems a legit use of tuple, no?

@HansBrende
Copy link

I am also having this same problem, which I fixed by downgrading to fastapi version 0.67.0. Specific stack trace details, etc: #3686 (I closed my issue as it was a duplicate of this issue).

@elrik75
Copy link

elrik75 commented Aug 22, 2021

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

@vdwees
Copy link

vdwees commented Oct 12, 2021

@Mause I have an API that uses tuples in a few places as well. At the moment it looks like I will be forced to pin to 0.67.0 indefinitely to avoid breaking changes to my API. Do you know if there is a plan to fix this regression?

@Mause
Copy link
Contributor

Mause commented Oct 12, 2021

@vdwees I'm not associated with the fastapi project so I can't help you sorry 😓

@vdwees
Copy link

vdwees commented Oct 12, 2021

@Mause sorry, thanks anyway

@vdwees
Copy link

vdwees commented Oct 12, 2021

I wonder if this old issue is related #1507

davelopez added a commit to davelopez/galaxy that referenced this issue Nov 15, 2021
There is a regression bug in FastAPI/Pydantic (see fastapi/fastapi#3665) that prevents the OpenAPI interactive documentation to render when we have models using `Tuple`.
Since Tuple is currently used just in one place, we can temporarily replace it with a simple List, we will lose a bit of validation but still is not worth reverting back to a previous version of FastAPI because of this.
@HansBrende
Copy link

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...

@elrik75
Copy link

elrik75 commented Nov 23, 2021

It's seems that FastAPI is not actively maintained anymore and nothing seems to be done to allow someone else to do it (source: #3970)
I guess we need to wait for a fork but this could take a lot of time.
I personally modified all the code that needed Tuples to a Dict with 2 keys.
By the way staying in 0.67.0 is not a big deal as there is almost no more evolution.

solomon-negusse added a commit to wri/gfw-data-api that referenced this issue Nov 29, 2021
solomon-negusse added a commit to wri/gfw-data-api that referenced this issue Nov 30, 2021
@vdwees
Copy link

vdwees commented Dec 12, 2021

It's seems that FastAPI is not actively maintained anymore and nothing seems to be done to allow someone else to do it (source: #3970)

I guess we need to wait for a fork but this could take a lot of time.

I personally modified all the code that needed Tuples to a Dict with 2 keys.

By the way staying in 0.67.0 is not a big deal as there is almost no more evolution.

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

@yangyaofei
Copy link

@elrik75 I have the same thought. Look at the merged PR, most recent PR is doc translations and update dependencies.

Here #1507 (comment) 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

@tiangolo
Copy link
Member

Thanks for the discussion everyone! This should be solved by #3874

It is available in FastAPI 0.73.0, released in the next hours. 🎉

For more context, check the last comment there: #3874 (comment)


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. 🎉

@martinezpl
Copy link

This issue is solved and can be closed.

@acidjunk
Copy link

@MarioIshac can you close the issue?

@github-actions
Copy link
Contributor

Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.

@tiangolo tiangolo reopened this Feb 27, 2023
@fastapi fastapi locked and limited conversation to collaborators Feb 27, 2023
@tiangolo tiangolo converted this issue into discussion #6531 Feb 27, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

9 participants