Skip to content
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

fix(deps): update dependency fastapi to <0.96 #255

Merged
merged 1 commit into from
Apr 8, 2023
Merged

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Apr 8, 2023

Mend Renovate

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
fastapi <0.89 -> <0.96 age adoption passing confidence

Release Notes

tiangolo/fastapi

v0.95.0

Compare Source

Highlights

This release adds support for dependencies and parameters using Annotated and recommends its usage. ✨

This has several benefits, one of the main ones is that now the parameters of your functions with Annotated would not be affected at all.

If you call those functions in other places in your code, the actual default values will be kept, your editor will help you notice missing required arguments, Python will require you to pass required arguments at runtime, you will be able to use the same functions for different things and with different libraries (e.g. Typer will soon support Annotated too, then you could use the same function for an API and a CLI), etc.

Because Annotated is standard Python, you still get all the benefits from editors and tools, like autocompletion, inline errors, etc.

One of the biggest benefits is that now you can create Annotated dependencies that are then shared by multiple path operation functions, this will allow you to reduce a lot of code duplication in your codebase, while keeping all the support from editors and tools.

For example, you could have code like this:

def get_current_user(token: str):

### authenticate user
    return User()

@&#8203;app.get("/items/")
def read_items(user: User = Depends(get_current_user)):
    ...

@&#8203;app.post("/items/")
def create_item(*, user: User = Depends(get_current_user), item: Item):
    ...

@&#8203;app.get("/items/{item_id}")
def read_item(*, user: User = Depends(get_current_user), item_id: int):
    ...

@&#8203;app.delete("/items/{item_id}")
def delete_item(*, user: User = Depends(get_current_user), item_id: int):
    ...

There's a bit of code duplication for the dependency:

user: User = Depends(get_current_user)

...the bigger the codebase, the more noticeable it is.

Now you can create an annotated dependency once, like this:

CurrentUser = Annotated[User, Depends(get_current_user)]

And then you can reuse this Annotated dependency:

CurrentUser = Annotated[User, Depends(get_current_user)]

@&#8203;app.get("/items/")
def read_items(user: CurrentUser):
    ...

@&#8203;app.post("/items/")
def create_item(user: CurrentUser, item: Item):
    ...

@&#8203;app.get("/items/{item_id}")
def read_item(user: CurrentUser, item_id: int):
    ...

@&#8203;app.delete("/items/{item_id}")
def delete_item(user: CurrentUser, item_id: int):
    ...

...and CurrentUser has all the typing information as User, so your editor will work as expected (autocompletion and everything), and FastAPI will be able to understand the dependency defined in Annotated. 😎

Roughly all the docs have been rewritten to use Annotated as the main way to declare parameters and dependencies. All the examples in the docs now include a version with Annotated and a version without it, for each of the specific Python versions (when there are small differences/improvements in more recent versions). There were around 23K new lines added between docs, examples, and tests. 🚀

The key updated docs are:

Special thanks to @​nzig for the core implementation and to @​adriangb for the inspiration and idea with Xpresso! 🚀

Features
  • ✨Add support for PEP-593 Annotated for specifying dependencies and parameters. PR #​4871 by @​nzig.
Docs
  • 📝 Tweak tip recommending Annotated in docs. PR #​9270 by @​tiangolo.
  • 📝 Update order of examples, latest Python version first, and simplify version tab names. PR #​9269 by @​tiangolo.
  • 📝 Update all docs to use Annotated as the main recommendation, with new examples and tests. PR #​9268 by @​tiangolo.

v0.94.1

Compare Source

Fixes

v0.94.0

Compare Source

Upgrades
Docs
Translations
  • 🌐 Add Russian translation for docs/ru/docs/history-design-future.md. PR #​5986 by @​Xewus.
Internal

v0.93.0

Compare Source

Features
  • ✨ Add support for lifespan async context managers (superseding startup and shutdown events). Initial PR #​2944 by @​uSpike.

Now, instead of using independent startup and shutdown events, you can define that logic in a single function with yield decorated with @asynccontextmanager (an async context manager).

For example:

from contextlib import asynccontextmanager

from fastapi import FastAPI

def fake_answer_to_everything_ml_model(x: float):
    return x * 42

ml_models = {}

@&#8203;asynccontextmanager
async def lifespan(app: FastAPI):

### Load the ML model
    ml_models["answer_to_everything"] = fake_answer_to_everything_ml_model
    yield

### Clean up the ML models and release the resources
    ml_models.clear()

app = FastAPI(lifespan=lifespan)

@&#8203;app.get("/predict")
async def predict(x: float):
    result = ml_models["answer_to_everything"](x)
    return {"result": result}

Note: This is the recommended way going forward, instead of using startup and shutdown events.

Read more about it in the new docs: Advanced User Guide: Lifespan Events.

Docs
  • ✏ Fix formatting in docs/en/docs/tutorial/metadata.md for ReDoc. PR #​6005 by @​eykamp.
Translations
Internal

v0.92.0

Compare Source

🚨 This is a security fix. Please upgrade as soon as possible.

Upgrades
  • ⬆️ Upgrade Starlette to 0.25.0. PR #​5996 by @​tiangolo.
    • This solves a vulnerability that could allow denial of service attacks by using many small multipart fields/files (parts), consuming high CPU and memory.
    • Only applications using forms (e.g. file uploads) could be affected.
    • For most cases, upgrading won't have any breaking changes.

v0.91.0

Compare Source

Upgrades
  • ⬆️ Upgrade Starlette version to 0.24.0 and refactor internals for compatibility. PR #​5985 by @​tiangolo.
    • This can solve nuanced errors when using middlewares. Before Starlette 0.24.0, a new instance of each middleware class would be created when a new middleware was added. That normally was not a problem, unless the middleware class expected to be created only once, with only one instance, that happened in some cases. This upgrade would solve those cases (thanks @​adriangb! Starlette PR #​2017). Now the middleware class instances are created once, right before the first request (the first time the app is called).
    • If you depended on that previous behavior, you might need to update your code. As always, make sure your tests pass before merging the upgrade.

v0.90.1

Compare Source

Upgrades
Docs
Translations
  • 🌐 Add Russian translation for docs/ru/docs/tutorial/cookie-params.md. PR #​5890 by @​bnzone.
Internal

v0.90.0

Compare Source

Upgrades
Docs
Translations
Internal

v0.89.1

Compare Source

Fixes
  • 🐛 Ignore Response classes on return annotation. PR #​5855 by @​Kludex. See the new docs in the PR below.
Docs
Translations

v0.89.0

Compare Source

Features
  • ✨ Add support for function return type annotations to declare the response_model. Initial PR #​1436 by @​uriyyo.

Now you can declare the return type / response_model in the function return type annotation:

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI()

class Item(BaseModel):
    name: str
    price: float

@&#8203;app.get("/items/")
async def read_items() -> list[Item]:
    return [
        Item(name="Portal Gun", price=42.0),
        Item(name="Plumbus", price=32.0),
    ]

FastAPI will use the return type annotation to perform:

  • Data validation
  • Automatic documentation
    • It could power automatic client generators
  • Data filtering

Before this version it was only supported via the response_model parameter.

Read more about it in the new docs: Response Model - Return Type.

Docs
Translations
Internal

Configuration

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

🚦 Automerge: Enabled.

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

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


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Mend Renovate. View repository job log here.

@renovate renovate bot added the dependencies Pull requests that update a dependency file label Apr 8, 2023
@codecov-commenter
Copy link

codecov-commenter commented Apr 8, 2023

Codecov Report

Merging #255 (99f5ffc) into main (46eb0c1) will not change coverage.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@           Coverage Diff           @@
##             main     #255   +/-   ##
=======================================
  Coverage   20.45%   20.45%           
=======================================
  Files          38       38           
  Lines        3222     3222           
  Branches      414      414           
=======================================
  Hits          659      659           
  Misses       2546     2546           
  Partials       17       17           
Impacted Files Coverage Δ
src/so_vits_svc_fork/__init__.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@renovate renovate bot merged commit 29c8cc0 into main Apr 8, 2023
@renovate renovate bot deleted the renovate/fastapi-0.x branch April 8, 2023 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant