Conversation
- `with_app_context_factory` returns an async wrapper for `async def` hook routes, which previously failed on every backend. - Both wrappers now set the app context only for the call instead of leaking it to the caller's context. - The FastAPI middleware also handles routes registered through Dash (hook routes, MCP), so `request_adapter()` works for them, and replays the JSON body it read so handlers reading the body don't hang. - Fix `hook_cleanup` resetting `"route"` instead of `"routes"`. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
|
Contributor
Dash performance benchmarks
growth = late-third / early-third per-op time; ~1 is flat, a large value means the per-op cost scales with accumulated state. machine scale vs baseline: 0.66x - divided out of the baseline ratios so they compare like for like (the absolute warn/fail ceilings are left un-scaled); calibrated on |
T4rk1n
marked this pull request as ready for review
October 2, 2026 16:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Hook routes (
dash.hooks.route) didn't work asasync def, and on the FastAPI backend they couldn't read the request at all. The same FastAPI issue also broke MCP (_mcp).Found while porting the Plotly Cloud dev tools publish route to the Quart/FastAPI backends (plotly/plotly-cloud-extension#112), which currently needs workarounds for both.
Changes
with_app_context_factorywrapped every hook route in a sync function, so anasync defroute returned 500 on Flask and Quart and failed on FastAPI. It now returns an async wrapper for coroutine functions (Flask needsflask[async]).app_contextin the caller's context, sodash.get_app()kept returning that app on the calling thread after the request. The sync wrapper now sets it only inside the copied context; the async wrapper sets it in the awaiting task's context and resets it afterwards. (Setting it in a copied context doesn't work for coroutines:ctx.run(func)only creates the coroutine there, and its body runs in the awaiting task's context.)_dash-*paths, sorequest_adapter()raised "No active request in context" in hook routes and in MCP. It now also handles exact-match routes registered through Dash (app.routes).hook_cleanupresethooks._ns["route"]instead of"routes", so hook routes leaked between tests.Test plan
tests/backend_tests/test_hook_routes.py: sync and async hook routes on Flask, Quart and FastAPI, reading JSON through the request adapter;get_app()returns the app serving the request with two apps; a FastAPI handler reading its own body. 4 of these fail without the fix.tests/backend_tests+tests/integration/test_hooks.py: 47 passed, 1 skippedtests/unit: 716 passed; the 3 failures also fail ondevlocally (no Firefox,flask-compressinstalled, port 8050 subprocess test)🤖 Generated with Claude Code