question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:16
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

12reactions
elrik75commented, 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

10reactions
tiangolocommented, Jan 23, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Release Notes - FastAPI
There are some possible breaking changes in the TestClient usage, but @Kludex built bump-testclient to help you automatize migrating your tests.
Read more >
Changes — Piccolo 0.102.0 documentation - Read the Docs
Fixed a bug with get_or_create and null columns (thanks to @powellnorma for reporting this issue). Updated the Starlite ASGI template, so it uses...
Read more >
/Releases.md | deno@v1.29.1 | Deno
A modern runtime for JavaScript and TypeScript.
Read more >
freqtrade: Versions - Openbase
Temporary fix for Kraken data-downloads, which broke mid-November due to an API update. Fix freqAI native installation on M1 Macs. freqAI. up to...
Read more >
Compare Packages Between Distributions - DistroWatch.com
The apache web server is listed as "httpd" and the Linux kernel is listed as "linux". The KDE desktop is represented by the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found