Skip to content

chore(deps): update dependency fastapi to ^0.85 - autoclosed

Oleg A. requested to merge renovate/fastapi-0-x into main

This MR contains the following updates:

Package Change Age Adoption Passing Confidence
fastapi ^0.66 -> ^0.85 age adoption passing confidence

Release Notes

tiangolo/fastapi

v0.85.1

Compare Source

Fixes
  • 🐛 Fix support for strings in OpenAPI status codes: default, 1XX, 2XX, 3XX, 4XX, 5XX. MR #​5187 by @​JarroVGIT.
Docs
Internal

v0.85.0

Compare Source

Features
  • Upgrade version required of Starlette from 0.19.1 to 0.20.4. Initial MR #​4820 by @​Kludex.
    • This includes several bug fixes in Starlette.
  • ️ Upgrade Uvicorn max version in public extras: all. From >=0.12.0,<0.18.0 to >=0.12.0,<0.19.0. MR #​5401 by @​tiangolo.
Internal
  • ️ Upgrade dependencies for doc and dev internal extras: Typer, Uvicorn. MR #​5400 by @​tiangolo.
  • ️ Upgrade test dependencies: Black, HTTPX, databases, types-ujson. MR #​5399 by @​tiangolo.
  • ️ Upgrade mypy and tweak internal type annotations. MR #​5398 by @​tiangolo.
  • 🔧 Update test dependencies, upgrade Pytest, move dependencies from dev to test. MR #​5396 by @​tiangolo.

v0.84.0

Compare Source

Breaking Changes

This version of FastAPI drops support for Python 3.6. 🔥 Please upgrade to a supported version of Python (3.7 or above), Python 3.6 reached the end-of-life a long time ago. 😅

  • 🔧 Update package metadata, drop support for Python 3.6, move build internals from Flit to Hatch. MR #​5240 by @​ofek.

v0.83.0

Compare Source

🚨 This is probably the last release (or one of the last releases) to support Python 3.6. 🔥

Python 3.6 reached the end-of-life and is no longer supported by Python since around a year ago.

You hopefully updated to a supported version of Python a while ago. If you haven't, you really should.

Features
  • Add support in jsonable_encoder for include and exclude with dataclasses. MR #​4923 by @​DCsunset.
Fixes
  • 🐛 Fix RuntimeError raised when HTTPException has a status code with no content. MR #​5365 by @​iudeen.
  • 🐛 Fix empty reponse body when default status_code is empty but the a Response parameter with response.status_code is set. MR #​5360 by @​tmeckel.
Docs
Internal

v0.82.0

Compare Source

🚨 This is probably the last release (or one of the last releases) to support Python 3.6. 🔥

Python 3.6 reached the end-of-life and is no longer supported by Python since around a year ago.

You hopefully updated to a supported version of Python a while ago. If you haven't, you really should.

Features
  • Export WebSocketState in fastapi.websockets. MR #​4376 by @​matiuszka.
  • Support Python internal description on Pydantic model's docstring. MR #​3032 by @​Kludex.
  • Update ORJSONResponse to support non str keys and serializing Numpy arrays. MR #​3892 by @​baby5.
Fixes
  • 🐛 Allow exit code for dependencies with yield to always execute, by removing capacity limiter for them, to e.g. allow closing DB connections without deadlocks. MR #​5122 by @​adriangb.
  • 🐛 Fix FastAPI People GitHub Action: set HTTPX timeout for GraphQL query request. MR #​5222 by @​iudeen.
  • 🐛 Make sure a parameter defined as required is kept required in OpenAPI even if defined as optional in another dependency. MR #​4319 by @​cd17822.
  • 🐛 Fix support for path parameters in WebSockets. MR #​3879 by @​davidbrochart.
Docs
Translations
Internal

v0.81.0

Compare Source

Features
  • Add ReDoc <noscript> warning when JS is disabled. MR #​5074 by @​evroon.
  • Add support for FrozenSet in parameters (e.g. query). MR #​2938 by @​juntatalor.
  • Allow custom middlewares to raise HTTPExceptions and propagate them. MR #​2036 by @​ghandic.
  • Preserve json.JSONDecodeError information when handling invalid JSON in request body, to support custom exception handlers that use its information. MR #​4057 by @​UKnowWhoIm.
Fixes
Docs
Translations
Internal

v0.80.0

Compare Source

Breaking Changes - Fixes

If you are using response_model with some type that doesn't include None but the function is returning None, it will now raise an internal server error, because you are returning invalid data that violates the contract in response_model. Before this release it would allow breaking that contract returning None.

For example, if you have an app like this:

from fastapi import FastAPI
from pydantic import BaseModel

class Item(BaseModel):
    name: str
    price: Optional[float] = None
    owner_ids: Optional[List[int]] = None

app = FastAPI()

@&#8203;app.get("/items/invalidnone", response_model=Item)
def get_invalid_none():
    return None

...calling the path /items/invalidnone will raise an error, because None is not a valid type for the response_model declared with Item.

You could also be implicitly returning None without realizing, for example:

from fastapi import FastAPI
from pydantic import BaseModel

class Item(BaseModel):
    name: str
    price: Optional[float] = None
    owner_ids: Optional[List[int]] = None

app = FastAPI()

@&#8203;app.get("/items/invalidnone", response_model=Item)
def get_invalid_none():
    if flag:
        return {"name": "foo"}

### if flag is False, at this point the function will implicitly return None

If you have path operations using response_model that need to be allowed to return None, make it explicit in response_model using Union[Something, None]:

from typing import Union

from fastapi import FastAPI
from pydantic import BaseModel

class Item(BaseModel):
    name: str
    price: Optional[float] = None
    owner_ids: Optional[List[int]] = None

app = FastAPI()

@&#8203;app.get("/items/invalidnone", response_model=Union[Item, None])
def get_invalid_none():
    return None

This way the data will be correctly validated, you won't have an internal server error, and the documentation will also reflect that this path operation could return None (or null in JSON).

Fixes
  • Upgrade Swagger UI copy of oauth2-redirect.html to include fixes for flavors of authorization code flows in Swagger UI. MR #​3439 initial MR by @​koonpeng.
  • Strip empty whitespace from description extracted from docstrings. MR #​2821 by @​and-semakin.
  • 🐛 Fix cached dependencies when using a dependency in Security() and other places (e.g. Depends()) with different OAuth2 scopes. MR #​2945 by @​laggardkernel.
  • 🎨 Update type annotations for response_model, allow things like Union[str, None]. MR #​5294 by @​tiangolo.
Translations

v0.79.1

Compare Source

Fixes
  • 🐛 Fix jsonable_encoder using include and exclude parameters for non-Pydantic objects. MR #​2606 by @​xaviml.
  • 🐛 Fix edge case with repeated aliases names not shown in OpenAPI. MR #​2351 by @​klaa97.
  • 📝 Add misc dependency installs to tutorial docs. MR #​2126 by @​TeoZosa.
Docs
Translations
Internal

v0.79.0

Compare Source

Fixes - Breaking Changes
  • 🐛 Fix removing body from status codes that do not support it. MR #​5145 by @​tiangolo.
    • Setting status_code to 204, 304, or any code below 200 (1xx) will remove the body from the response.
    • This fixes an error in Uvicorn that otherwise would be thrown: RuntimeError: Response content longer than Content-Length.
    • This removes fastapi.openapi.constants.STATUS_CODES_WITH_NO_BODY, it is replaced by a function in utils.
Translations
Internal

v0.78.0

Compare Source

Features
  • Add support for omitting ... as default value when declaring required parameters with:

  • Path()

  • Query()

  • Header()

  • Cookie()

  • Body()

  • Form()

  • File()

New docs at Tutorial - Query Parameters and String Validations - Make it required. MR #​4906 by @​tiangolo.

Up to now, declaring a required parameter while adding additional validation or metadata needed using ... (Ellipsis).

For example:

from fastapi import Cookie, FastAPI, Header, Path, Query

app = FastAPI()

@&#8203;app.get("/items/{item_id}")
def main(
    item_id: int = Path(default=..., gt=0),
    query: str = Query(default=..., max_length=10),
    session: str = Cookie(default=..., min_length=3),
    x_trace: str = Header(default=..., title="Tracing header"),
):
    return {"message": "Hello World"}

...all these parameters are required because the default value is ... (Ellipsis).

But now it's possible and supported to just omit the default value, as would be done with Pydantic fields, and the parameters would still be required.

For example, this is now supported:

from fastapi import Cookie, FastAPI, Header, Path, Query

app = FastAPI()

@&#8203;app.get("/items/{item_id}")
def main(
    item_id: int = Path(gt=0),
    query: str = Query(max_length=10),
    session: str = Cookie(min_length=3),
    x_trace: str = Header(title="Tracing header"),
):
    return {"message": "Hello World"}

To declare parameters as optional (not required), you can set a default value as always, for example using None:

from typing import Union
from fastapi import Cookie, FastAPI, Header, Path, Query

app = FastAPI()

@&#8203;app.get("/items/{item_id}")
def main(
    item_id: int = Path(gt=0),
    query: Union[str, None] = Query(default=None, max_length=10),
    session: Union[str, None] = Cookie(default=None, min_length=3),
    x_trace: Union[str, None] = Header(default=None, title="Tracing header"),
):
    return {"message": "Hello World"}
Docs
Translations
Internal

v0.77.1

Compare Source

Upgrades
Docs
Translations
Internal

v0.77.0

Compare Source

Upgrades
  • Upgrade Starlette from 0.18.0 to 0.19.0. MR #​4488 by @​Kludex.
    • When creating an explicit JSONResponse the content argument is now required.
Docs
Translations

v0.76.0

Compare Source

Upgrades
Internal

v0.75.2

Compare Source

This release includes upgrades to third-party packages that handle security issues. Although there's a chance these issues don't affect you in particular, please upgrade as soon as possible.

Fixes
Upgrades
  • ️ Update ujson ranges for CVE-2021-45958. MR #​4804 by @​tiangolo.
  • ️ Upgrade dependencies upper range for extras "all". MR #​4803 by @​tiangolo.
  • Upgrade Swagger UI - swagger-ui-dist@4. This handles a security issue in Swagger UI itself where it could be possible to inject HTML into Swagger UI. Please upgrade as soon as you can, in particular if you expose your Swagger UI (/docs) publicly to non-expert users. MR #​4347 by @​RAlanWright.
Internal
  • 🔧 Update sponsors, add: ExoFlare, Ines Course; remove: Dropbase, Vim.so, Calmcode; update: Striveworks, TalkPython and TestDriven.io. MR #​4805 by @​tiangolo.
  • ️ Upgrade Codecov GitHub Action. MR #​4801 by @​tiangolo.

v0.75.1

Compare Source

Translations
Internal

v0.75.0

Compare Source

Features

v0.74.1

Compare Source

Features
  • Include route in scope to allow middleware and other tools to extract its information. MR #​4603 by @​tiangolo.

v0.74.0

Compare Source

Breaking Changes
  • Update internal AsyncExitStack to fix context for dependencies with yield. MR #​4575 by @​tiangolo.

Dependencies with yield can now catch HTTPException and custom exceptions. For example:

async def get_database():
    with Session() as session:
        try:
            yield session
        except HTTPException:
            session.rollback()
            raise
        finally:
            session.close()

After the dependency with yield handles the exception (or not) the exception is raised again. So that any exception handlers can catch it, or ultimately the default internal ServerErrorMiddleware.

If you depended on exceptions not being received by dependencies with yield, and receiving an exception breaks the code after yield, you can use a block with try and finally:

async def do_something():
    try:
        yield something
    finally:
        some_cleanup()

...that way the finally block is run regardless of any exception that might happen.

Features
  • The same MR #​4575 from above also fixes the contextvars context for the code before and after yield. This was the main objective of that MR.

This means that now, if you set a value in a context variable before yield, the value would still be available after yield (as you would intuitively expect). And it also means that you can reset the context variable with a token afterwards.

For example, this works correctly now:

from contextvars import ContextVar
from typing import Any, Dict, Optional

legacy_request_state_context_var: ContextVar[Optional[Dict[str, Any]]] = ContextVar(
    "legacy_request_state_context_var", default=None
)

async def set_up_request_state_dependency():
    request_state = {"user": "deadpond"}
    contextvar_token = legacy_request_state_context_var.set(request_state)
    yield request_state
    legacy_request_state_context_var.reset(contextvar_token)

...before this change it would raise an error when resetting the context variable, because the contextvars context was different, because of the way it was implemented.

Note: You probably don't need contextvars, and you should probably avoid using them. But they are powerful and useful in some advanced scenarios, for example, migrating from code that used Flask's g semi-global variable.

Technical Details: If you want to know more of the technical details you can check out the MR description #​4575.

Internal

v0.73.0

Compare Source

Features
Docs
Fixes
Internal

v0.72.0

Compare Source

Features
Docs
Translations
Internal

v0.71.0

Compare Source

Features
  • Add docs and tests for Python 3.9 and Python 3.10. MR #​3712 by @​tiangolo.
    • You can start with Python Types Intro, it explains what changes between different Python versions, in Python 3.9 and in Python 3.10.
    • All the FastAPI docs are updated. Each code example in the docs that could use different syntax in Python 3.9 or Python 3.10 now has all the alternatives in tabs.
  • ️ Upgrade Starlette to 0.17.1. MR #​4145 by @​simondale00.
Internal

v0.70.1

Compare Source

There's nothing interesting in this particular FastAPI release. It is mainly to enable/unblock the release of the next version of Pydantic that comes packed with features and improvements. 🤩

Fixes
Translations
Internal

v0.70.0

Compare Source

This release just upgrades Starlette to the latest version, 0.16.0, which includes several bug fixes and some small breaking changes.

These last three consecutive releases are independent so that you can migrate gradually:

  • First to FastAPI 0.68.2, with no breaking changes, but upgrading all the sub-dependencies.
  • Next to FastAPI 0.69.0, which upgrades Starlette to 0.15.0, with AnyIO support, and a higher chance of having breaking changes in your code.
  • Finally to FastAPI 0.70.0, just upgrading Starlette to the latest version 0.16.0 with additional bug fixes.

This way, in case there was a breaking change for your code in one of the releases, you can still benefit from the previous upgrades.

Breaking Changes - Upgrade

Also upgrades the ranges of optional dependencies:

  • "jinja2 >=2.11.2,<4.0.0"
  • "itsdangerous >=1.1.0,<3.0.0"

v0.69.0

Compare Source

Breaking Changes - Upgrade

This release adds support for Trio.

It upgrades the version of Starlette to 0.15.0, now based on AnyIO, and the internal async components in FastAPI are now based on AnyIO as well, making it compatible with both asyncio and Trio.

You can read the docs about running FastAPI with Trio using Hypercorn.

This release also removes graphene as an optional dependency for GraphQL. If you need to work with GraphQL, the recommended library now is Strawberry. You can read the new FastAPI with GraphQL docs.

Features
Docs
Translations
Internal

v0.68.2

Compare Source

This release has no breaking changes. 🎉

It upgrades the version ranges of sub-dependencies to allow applications using FastAPI to easily upgrade them.

Soon there will be a new FastAPI release upgrading Starlette to take advantage of recent improvements, but as that has a higher chance of having breaking changes, it will be in a separate release.

Features
Docs
  • 📝 Update GraphQL docs, recommend Strawberry. MR #​3981 by @​tiangolo.
  • 📝 Re-write and extend Deployment guide: Concepts, Uvicorn, Gunicorn, Docker, Containers, Kubernetes. MR #​3974 by @​tiangolo.
  • 📝 Upgrade HTTPS guide with more explanations and diagrams. MR #​3950 by @​tiangolo.
Translations
Internal

v0.68.1

Compare Source

Translations
Internal

v0.68.0

Compare Source

Features
Docs
Translations
Internal

v0.67.0

Compare Source

Features
Docs
Internal

v0.66.1

Compare Source

Translations
Internal
  • 🔧 Configure strict pytest options and update/refactor tests. Upgrade pytest to >=6.2.4,<7.0.0 and pytest-cov to >=2.12.0,<3.0.0. Initial MR #​2790 by @​graingert.
  • ️ Upgrade python-jose dependency to >=3.3.0,<4.0.0 for tests. MR #​3468 by @​tiangolo.

Configuration

📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this MR and you won't be reminded about this update again.


  • If you want to rebase/retry this MR, click this checkbox.

This MR has been generated by Renovate Bot.

Merge request reports