Skip to content

fix(deps): update dependency fastapi to ^0.83.0

renovate requested to merge renovate/fastapi-0.x into master

This MR contains the following updates:

Package Change Age Adoption Passing Confidence
fastapi ^0.71.0 -> ^0.83.0 age adoption passing confidence

Release Notes

tiangolo/fastapi

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

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.

Edited by Kevin Morris

Merge request reports