diff --git a/fastapi/routing.py b/fastapi/routing.py index a13763535d..7fd1dd283c 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -73,9 +73,9 @@ from fastapi.utils import ( is_body_allowed_for_status_code, ) from starlette import routing -from starlette.background import BackgroundTasks from starlette._exception_handler import wrap_app_handling_exceptions from starlette._utils import is_async_callable +from starlette.background import BackgroundTasks from starlette.concurrency import iterate_in_threadpool, run_in_threadpool from starlette.datastructures import FormData from starlette.exceptions import HTTPException @@ -684,9 +684,7 @@ def get_request_handler( # Merge injected BackgroundTasks with the Response's # own background task so neither set is lost. original = raw_response.background - merged = BackgroundTasks( - solved_result.background_tasks.tasks - ) + merged = BackgroundTasks(solved_result.background_tasks.tasks) if isinstance(original, BackgroundTasks): merged.tasks.extend(original.tasks) else: diff --git a/tests/test_background_tasks_merge.py b/tests/test_background_tasks_merge.py index 89e640f3ef..3bfff385f4 100644 --- a/tests/test_background_tasks_merge.py +++ b/tests/test_background_tasks_merge.py @@ -8,7 +8,7 @@ injected tasks. See: https://github.com/fastapi/fastapi/issues/11215 """ -from fastapi import FastAPI, BackgroundTasks +from fastapi import BackgroundTasks, FastAPI from fastapi.testclient import TestClient from starlette.background import BackgroundTask from starlette.background import BackgroundTasks as StarletteBackgroundTasks