Releases: tiangolo/fastapi
0.75.2
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
- ✅ Fix new/recent tests with new fixed
ValidationError
JSON Schema. PR #4806 by @tiangolo. - 🐛 Fix JSON Schema for
ValidationError
at fieldloc
. PR #3810 by @dconathan. - 🐛 Fix support for prefix on APIRouter WebSockets. PR #2640 by @Kludex.
Upgrades
- ⬆️ Update ujson ranges for CVE-2021-45958. PR #4804 by @tiangolo.
- ⬆️ Upgrade dependencies upper range for extras "all". PR #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. PR #4347 by @RAlanWright.
Internal
0.75.1
Translations
- 🌐 Start Dutch translations. PR #4703 by @tiangolo.
- 🌐 Start Persian/Farsi translations. PR #4243 by @aminalaee.
- ✏ Reword sentence about handling errors. PR #1993 by @khuhroproeza.
Internal
- 👥 Update FastAPI People. PR #4752 by @github-actions[bot].
- ➖ Temporarily remove typer-cli from dependencies and upgrade Black to unblock Pydantic CI. PR #4754 by @tiangolo.
- 🔧 Add configuration to notify Dutch translations. PR #4702 by @tiangolo.
- 👥 Update FastAPI People. PR #4699 by @github-actions[bot].
- 🐛 Fix FastAPI People generation to include missing file in commit. PR #4695 by @tiangolo.
- 🔧 Update Classiq sponsor links. PR #4688 by @tiangolo.
- 🔧 Add Classiq sponsor. PR #4671 by @tiangolo.
- 📝 Add Jina's QA Bot to the docs to help people that want to ask quick questions. PR #4655 by @tiangolo based on original PR #4626 by @hanxiao.
0.75.0
0.74.1
0.74.0
Breaking Changes
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 PR #4575 from above also fixes the
contextvars
context for the code before and afteryield
. This was the main objective of that PR.
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 PR description #4575.
Internal
0.73.0
Features
- ✨ Add support for declaring
UploadFile
parameters without explicitFile()
. PR #4469 by @tiangolo. New docs: Request Files - File Parameters with UploadFile. - ✨ Add support for tags with Enums. PR #4468 by @tiangolo. New docs: Path Operation Configuration - Tags with Enums.
- ✨ Allow hiding from OpenAPI (and Swagger UI)
Query
,Cookie
,Header
, andPath
parameters. PR #3144 by @astraldawn. New docs: Query Parameters and String Validations - Exclude from OpenAPI.
Docs
Fixes
- 🐛 Fix bug preventing to use OpenAPI when using tuples. PR #3874 by @victorbenichoux.
- 🐛 Prefer custom encoder over defaults if specified in
jsonable_encoder
. PR #2061 by @viveksunder.
Internal
0.72.0
Features
- ✨ Enable configuring Swagger UI parameters. Original PR #2568 by @jmriebold. Here are the new docs: Configuring Swagger UI.
Docs
Translations
- 🌐 Update Chinese translation for
docs/help-fastapi.md
. PR #3847 by @jaystone776. - 🌐 Fix Korean translation for
docs/ko/docs/index.md
. PR #4195 by @kty4119. - 🌐 Add Polish translation for
docs/pl/docs/index.md
. PR #4245 by @MicroPanda123. - 🌐 Add Chinese translation for
docs\tutorial\path-operation-configuration.md
. PR #3312 by @jaystone776.
Internal
0.71.0
Features
- ✨ Add docs and tests for Python 3.9 and Python 3.10. PR #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. PR #4145 by @simondale00.
Internal
0.70.1
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
- 🐛 Fix JSON Schema for dataclasses, supporting the fixes in Pydantic 1.9. PR #4272 by @PrettyWood.
Translations
- 🌐 Add Korean translation for
docs/tutorial/request-forms-and-files.md
. PR #3744 by @NinaHwang. - 🌐 Add Korean translation for
docs/tutorial/request-files.md
. PR #3743 by @NinaHwang. - 🌐 Add portuguese translation for
docs/tutorial/query-params-str-validations.md
. PR #3965 by @leandrodesouzadev. - 🌐 Add Korean translation for
docs/tutorial/response-status-code.md
. PR #3742 by @NinaHwang. - 🌐 Add Korean translation for Tutorial - JSON Compatible Encoder. PR #3152 by @NEONKID.
- 🌐 Add Korean translation for Tutorial - Path Parameters and Numeric Validations. PR #2432 by @hard-coders.
- 🌐 Add Korean translation for
docs/ko/docs/deployment/versions.md
. PR #4121 by @DevDae. - 🌐 Fix Korean translation for
docs/ko/docs/tutorial/index.md
. PR #4193 by @kimjaeyoonn. - 🔧 Add CryptAPI sponsor. PR #4264 by @tiangolo.
- 📝 Update
docs/tutorial/dependencies/classes-as-dependencies
: Add type of query parameters in a description ofClasses as dependencies
. PR #4015 by @0417taehyun. - 🌐 Add French translation for Tutorial - First steps. PR #3455 by @Smlep.
- 🌐 Add French translation for
docs/tutorial/path-params.md
. PR #3548 by @Smlep. - 🌐 Add French translation for
docs/tutorial/query-params.md
. PR #3556 by @Smlep. - 🌐 Add Turkish translation for
docs/python-types.md
. PR #3926 by @BilalAlpaslan.
Internal
- 👥 Update FastAPI People. PR #4274 by @github-actions[bot].
0.70.0
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 to0.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 version0.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"