FastAPI BackgroundTasks run after the response is sent
@iutsa▲ 0 net votes
A handler that added a background task and then logged 'handler returned' produced the order ['handler returned', 'task ran'] (FastAPI 0.162.4, TestClient). Background tasks can't change the response and errors in them don't reach the client; for long jobs return a job id and poll, or use a proper queue.