Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).

### Fixed
- [#3805](https://github.com/plotly/dash/pull/3805) Fix FastAPI POST routes deadlock caused by middleware consuming request body. Fixes [#3801](https://github.com/plotly/dash/issues/3801).
- [#3819](https://github.com/plotly/dash/pull/3819) Fix `RuntimeError: No active request in context` when a non-Dash path falls through to the FastAPI catch-all route. Fixes [#3812](https://github.com/plotly/dash/issues/3812).

## [4.2.0] - 2026-06-01 - *The Freedom Update*

Expand Down
8 changes: 6 additions & 2 deletions dash/backends/_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,12 @@ def _setup_catchall(self):
try:
dash_app = get_app()

async def catchall(_request: Request):
return Response(content=dash_app.index(), media_type="text/html")
async def catchall(request: Request):
token = set_current_request(request)
try:
return Response(content=dash_app.index(), media_type="text/html")
finally:
reset_current_request(token)

# pylint: disable=protected-access
self.add_url_rule("{path:path}", catchall, methods=["GET"])
Expand Down
19 changes: 19 additions & 0 deletions tests/backend_tests/test_preconfig_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,3 +334,22 @@ async def echo_post(request: Request):
)
assert resp.status_code == 200
assert resp.json() == {"echo": {"hello": "world"}}


def test_fastapi_catchall_request_context(dash_duo):
"""Test that non-Dash paths falling through to the catch-all route work.

Regression test for https://github.com/plotly/dash/issues/3812
The catch-all route renders ``dash_app.index()``, which needs a request
context; without it the request raised ``RuntimeError: No active request in
context`` and returned a 500.
"""
import requests

app = Dash(__name__, backend="fastapi")
app.layout = html.Div("Dash is running")

dash_duo.start_server(app)

resp = requests.get(f"{dash_duo.server_url}/some/non-dash/path", timeout=5)
assert resp.status_code == 200