Charisn
d762eb6405
Fix _endpoint_context_cache using id() which risks stale entries and memory leaks
The _endpoint_context_cache in routing.py used id(func) as dict keys to
cache endpoint context (source file, line number, function name) for
error messages. This has two problems:
1. ID reuse after garbage collection. Python id() returns the memory
address of an object. Once an object is garbage collected, its ID can
be reassigned to a newly created object. If an endpoint function were
deallocated and a new function reused the same ID, the cache would
return stale context (wrong file, line, function name) for error
messages.
2. No eviction. The module-level dict grows unboundedly for every unique
endpoint function. In scenarios where FastAPI instances are
dynamically created and destroyed in a single process (e.g., test
suites running hundreds of apps), endpoint functions and their
closures are kept alive indefinitely by the cache, leaking memory.
Fix: replace the plain dict with a weakref.WeakKeyDictionary keyed on
the function object itself. This solves both problems: keys are looked
up by object identity (no ID collision), and entries are automatically
evicted when the endpoint function is garbage collected, allowing the
function and its closure to be reclaimed.
Endpoint functions always support weak references (regular def / async
def), so WeakKeyDictionary is safe for this use case.
4 months ago
Sebastián Ramírez
a2e51363c7
🔖 Release version 0.129.0
4 months ago
Sebastián Ramírez
3da206c06d
🎨 Update internal types for Python 3.10 ( #14898 )
4 months ago
Sebastián Ramírez
ad4e8e0060
➖ Drop support for Python 3.9 ( #14897 )
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
4 months ago
Sebastián Ramírez
bdd20051c4
🔖 Release version 0.128.8
4 months ago
Sebastián Ramírez
8f82c94de0
🔖 Release version 0.128.7
4 months ago
Sebastián Ramírez
25270fcee0
♻️ Simplify reading files in memory, do it sequentially instead of (fake) parallel ( #14884 )
4 months ago
Javier Sánchez Castro
df950111fe
✨ Show a clear error on attempt to include router into itself ( #14258 )
Co-authored-by: Javier Sánchez <[email protected] >
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Motov Yurii <[email protected] >
4 months ago
rijenkii
66dc695071
✨ Replace `dict` by `Mapping` on `HTTPException.headers` ( #12997 )
Co-authored-by: Alejandra <[email protected] >
Co-authored-by: Motov Yurii <[email protected] >
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
4 months ago
Sebastián Ramírez
0a4033aeee
🔖 Release version 0.128.6
4 months ago
Motov Yurii
ed2512a5ec
🐛 Fix `on_startup` and `on_shutdown` parameters of `APIRouter` ( #14873 )
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
4 months ago
Sebastián Ramírez
dedf1409fe
🔖 Release version 0.128.5
4 months ago
Sebastián Ramírez
2e7d3754cd
♻️ Refactor and simplify Pydantic v2 (and v1) compatibility internal utils ( #14862 )
4 months ago
Sebastián Ramírez
8eac94bd91
🔖 Release version 0.128.4
4 months ago
Sebastián Ramírez
d59fbc3494
♻️ Refactor internals, simplify Pydantic v2/v1 utils, `create_model_field`, better types for `lenient_issubclass` ( #14860 )
4 months ago
Sebastián Ramírez
cf55bade7e
♻️ Simplify internals, remove Pydantic v1 only logic, no longer needed ( #14857 )
4 months ago
Sebastián Ramírez
3c49346238
♻️ Refactor internals, cleanup unneeded Pydantic v1 specific logic ( #14856 )
4 months ago
Sebastián Ramírez
36985f5f25
🔖 Release version 0.128.3
4 months ago
Sebastián Ramírez
f9f7992604
♻️ Re-implement `on_event` in FastAPI for compatibility with the next Starlette, while keeping backwards compatibility ( #14851 )
4 months ago
Sebastián Ramírez
79406a4b04
🔖 Release version 0.128.2
4 months ago
Kanetsuna Masaya
c5fd75a321
🐛 Fix using `Json[list[str]]` type (issue #10997 ) ( #14616 )
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: Motov Yurii <[email protected] >
Co-authored-by: Sebastián Ramírez <[email protected] >
4 months ago
Albin Skott
97145588f5
✨ Add support for PEP695 `TypeAliasType` ( #13920 )
Co-authored-by: lokidev <[email protected] >
Co-authored-by: Motov Yurii <[email protected] >
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Yurii Motov <[email protected] >
Co-authored-by: Sebastián Ramírez <[email protected] >
4 months ago
Jonathan Fulton
b49435becd
✨ Allow `Response` type hint as dependency annotation ( #14794 )
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: Motov Yurii <[email protected] >
Co-authored-by: Sebastián Ramírez <[email protected] >
4 months ago
Sebastián Ramírez
1de0de56c8
🔖 Release version 0.128.1
4 months ago
Jonathan Fulton
75c47187f3
🐛 Update `ValidationError` schema to include `input` and `ctx` ( #14791 )
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
4 months ago
Sebastián Ramírez
440bfd70a9
🎨 Tweak types for mypy ( #14816 )
4 months ago
Mickaël Guérin
09f5941f0e
🐛 Fix TYPE_CHECKING annotations for Python 3.14 (PEP 649) ( #14789 )
4 months ago
Cecilia Madrid
1d96b3e3f1
🐛 Strip whitespaces from `Authorization` header credentials ( #14786 )
4 months ago
Joab
741f77d571
✨ Add `viewport` meta tag to improve Swagger UI on mobile devices ( #14777 )
4 months ago
mvanderlee
0748214c43
🏷️ Re-export `IncEx` type from Pydantic instead of duplicating it ( #14641 )
4 months ago
Anton
41352de24c
🚸 Improve error message for invalid query parameter type annotations ( #14479 )
Co-authored-by: Anton.D <[email protected] >
Co-authored-by: Motov Yurii <[email protected] >
4 months ago
DJ Melisso
08dad5c69f
🐛 Fix OpenAPI duplication of `anyOf` refs for app-level responses with specified `content` and `model` as `Union` ( #14463 )
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: Motov Yurii <[email protected] >
4 months ago
Motov Yurii
3a41403ccd
📝 Add links to related sections of docs to docstrings ( #14776 )
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
4 months ago
Motov Yurii
dc3278654f
📝 Use `WSGIMiddleware` from `a2wsgi` instead of deprecated `fastapi.middleware.wsgi.WSGIMiddleware` ( #14756 )
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
4 months ago
Sebastián Ramírez
261736ab4c
💡 Update comment for Pydantic internals ( #14814 )
4 months ago
Motov Yurii
f3f498100f
👷 Run mypy by pre-commit ( #14806 )
Co-authored-by: Sebastián Ramírez <[email protected] >
4 months ago
Sebastián Ramírez
8322a4445a
🔖 Release version 0.128.0
6 months ago
Sebastián Ramírez
e300630551
➖ Drop support for `pydantic.v1` ( #14609 )
6 months ago
Sebastián Ramírez
cd90c78391
🔖 Release version 0.127.1
6 months ago
Sebastián Ramírez
535b5daa31
🔊 Add a custom `FastAPIDeprecationWarning` ( #14605 )
6 months ago
Sebastián Ramírez
c4a1ab5036
🔖 Release version 0.127.0
6 months ago
Sebastián Ramírez
6e42bcd8ce
🔊 Add deprecation warnings when using `pydantic.v1` ( #14583 )
6 months ago
Sebastián Ramírez
10252b1937
🔖 Release version 0.126.0
6 months ago
Sebastián Ramírez
e2cd8a4201
➖ Drop support for Pydantic v1, keeping short temporary support for Pydantic v2's `pydantic.v1` ( #14575 )
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
6 months ago
Sebastián Ramírez
c75f17d483
🔖 Release version 0.125.0
6 months ago
Sebastián Ramírez
1c4fc96c91
♻️ Upgrade internal syntax to Python 3.9+ 🎉 ( #14564 )
6 months ago
Sebastián Ramírez
ed97d9dc0c
⚰️ Remove Python 3.8 from CI and remove Python 3.8 examples from source docs ( #14559 )
Co-authored-by: Yurii Motov <[email protected] >
Co-authored-by: Motov Yurii <[email protected] >
6 months ago
Sebastián Ramírez
b1d9769f97
🔖 Release version 0.124.4
6 months ago
Motov Yurii
d86c47477e
🐛 Fix parameter aliases ( #14371 )
Co-authored-by: Sebastián Ramírez <[email protected] >
6 months ago
Sebastián Ramírez
3fe6522aae
🔖 Release version 0.124.3
6 months ago