Commit Graph

9 Commits

Author SHA1 Message Date
Sebastián Ramírez e329d78f86
🐛 Fix support for `StreamingResponse`s with dependencies with `yield` or `UploadFile`s, close after the response is done (#14099)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-09-29 05:29:38 +02:00
Sebastián Ramírez 3a3ad5d66d
⬆️ Upgrade version of Ruff and reformat (#12032)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-08-16 23:13:50 -05:00
Sebastián Ramírez bf771bd781
🐛 Fix unhandled growing memory for internal server errors, refactor dependencies with `yield` and `except` to require raising again as in regular Python (#11191)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-02-25 00:06:37 +01:00
Sebastián Ramírez a4aa79e0b4
Add support for raising exceptions (including `HTTPException`) in dependencies with `yield` in the exit code, do not support them in background tasks (#10831)
* ♻️ Refactor dependency AsyncExitStack logic, exit dependencies after creating the response, before sending it

*  Update tests for dependencies exit, check they are finished before the response is sent

* 🔥 Remove ExitAsyncStackMiddleware as it's no longer needed

* 📝 Update docs for dependencies with yield

* 📝 Update release notes

* 📝 Add source examples for new dependencies with yield raising

*  Add tests for new dependencies raising after yield

* 📝 Update release notes
2023-12-25 18:57:35 +01:00
Sebastián Ramírez 9d56a3cb59
Update internal `AsyncExitStack` to fix context for dependencies with `yield` (#4575) 2022-02-17 13:40:12 +01:00
Nima Mashhadi M. Reza da9b5201c4
🔧 Add Flake8 linting (#1774)
Co-authored-by: nimashadix <nimashadix@pop-os.localdomain>
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
2020-08-09 12:54:05 +02:00
Samuel Colvin e9b189e9f2
Improve test debugging (#1222) 2020-04-08 06:37:38 +02:00
Sebastián Ramírez 0ac9b3ee5c
Re-export utils from Starlette (#1064)
*  Re-export main features used from Starlette to simplify developer's code

* ♻️ Refactor Starlette exports

* ♻️ Refactor tutorial examples to use re-exported utils from Starlette

* 📝 Add examples for all middlewares

* 📝 Add new docs for middlewares

* 📝 Add examples for custom responses

* 📝 Extend docs for custom responses

* 📝 Update docs and add notes explaining re-exports from Starlette everywhere

* 🍱 Update screenshot for HTTP status

* 🔧 Update MkDocs config with new content

* ♻️ Refactor tests to use re-exported utils from Starlette

*  Re-export WebSocketDisconnect from Starlette for tests

*  Add extra tests for extra re-exported middleware

*  Add tests for re-exported responses from Starlette

*  Add docs about mounting WSGI apps

*  Add Flask as a dependency to test WSGIMiddleware

*  Test WSGIMiddleware example
2020-03-01 21:49:20 +01:00
Sebastián Ramírez 3f9f4a0f8f
Add dependencies with yield (used as context managers) (#595)
*  Add development/testing dependencies for Python 3.6

*  Add concurrency submodule with contextmanager_in_threadpool

*  Add AsyncExitStack to ASGI scope in FastAPI app call

*  Use async stack for contextmanager-able dependencies

including running in threadpool sync dependencies

*  Add tests for contextmanager dependencies

including internal raise checks when exceptions should be handled and when not

*  Add test for fake asynccontextmanager raiser

* 🐛 Fix mypy errors and coverage

* 🔇 Remove development logs and prints

*  Add tests for sub-contextmanagers, background tasks, and sync functions

* 🐛 Fix mypy errors for Python 3.7

* 💬 Fix error texts for clarity

* 📝 Add docs for dependencies with yield

*  Update SQL with SQLAlchemy tutorial to use dependencies with yield

and add an alternative with a middleware (from the old tutorial)

*  Update SQL tests to remove DB file during the same tests

*  Add tests for example with middleware

as a copy from the tests with dependencies with yield, removing the DB in the tests

* ✏️ Fix typos with suggestions from code review

Co-Authored-By: dmontagu <35119617+dmontagu@users.noreply.github.com>
2019-10-09 13:01:58 -05:00