[BUG] Plotly Cloud devtool route crashes with FastAPI and Quart backends
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 65/100
调研方向
The issue is in plotly_cloud/_devtool_hooks.py line 36 where flask.request.get_json() is called. First, understand how Dash registers routes for different backends (FastAPI, Quart, Flask). Look at the Dash server initialization and route registration logic. Check if the devtool route should be conditionally registered based on the backend. The fix likely involves checking the request context or using backend-agnostic request data access. Run the provided reproduction script to confirm the crash.
由索引模型根据 Issue 内容生成。
描述
Describe your context
- OS: Linux on WSL2
- Python: 3.13.11
- Browser: N/A (server-side issue reproduced with backend test clients)
Dash 4.5.0rc0 / FastAPI environment:
dash 4.5.0rc0
plotly-cloud 0.5.0
fastapi 0.141.1
Dash 4.5.0rc0 / Quart environment (isolated):
dash 4.5.0rc0
plotly-cloud 0.5.0
quart 0.23.1
Describe the bug
With the FastAPI or Quart backend, the Plotly Cloud devtool registers POST /_plotly_cloud_publish, but its handler calls flask.request.get_json(). Neither backend provides a Flask request context, so this route returns HTTP 500:
File "plotly_cloud/_devtool_hooks.py", line 36, in plotly_cloud_publish_rpc
data = flask.request.get_json()
RuntimeError: Working outside of request context.
This is exposed by default in Dash 4.5.0rc0 because #3947 made plotly-cloud a default dependency. To distinguish the dependency change from the underlying compatibility issue, I tested isolated environments:
| Environment | Cloud route registered? | POST result |
|---|---|---|
| Dash 4.4.1, without Plotly Cloud | No | N/A |
| Dash 4.4.1 + Plotly Cloud 0.5.0 | Yes | 500 (FastAPI and Quart) |
| Dash 4.5.0rc0, without explicitly installing Plotly Cloud | Yes | 500 (FastAPI and Quart) |
Steps to reproduce
Install dash[fastapi,quart]==4.5.0rc0 and httpx, then run the following script in separate processes with fastapi and quart as the argument:
import asyncio
import sys
from dash import Dash, html
from fastapi.testclient import TestClient
backend = sys.argv[1]
app = Dash(__name__, backend=backend)
app.layout = html.Div("Hello")
app.enable_dev_tools(debug=True, dev_tools_ui=True)
if backend == "fastapi":
response = TestClient(
app.server, raise_server_exceptions=False
).post("/_plotly_cloud_publish", json={})
else:
response = asyncio.run(
app.server.test_client().post("/_plotly_cloud_publish", json={})
)
print(response.status_code) # 500 for both backends
Expected behavior
Enabling Dash Dev Tools with FastAPI or Quart should not register a Plotly Cloud route that crashes. The integration should support these backends or omit its devtool and route when they are unsupported.
Screenshots
Not applicable; this is a server-side error.
- 主要语言
- Python
- 星标
- 24.4k
- 派生
- 2.3k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 19
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
plotly/dash 的其他 Issue
-
good first issue P3 size: 1 task
难度 2/5 1-3 小时 新手友好度 68/100
-
enhancement P2 size: 5
难度 5/5 一周以上 新手友好度 45/100
-
enhancement P3 size: 10+
-
P2 size: 1 task
-
enhancement P3 size: 1
难度 3/5 1-2 天 新手友好度 72/100
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
xinnan-tech/xiaozhi-fde-talk#263 ·
-
rules
难度 1/5 1 小时以内 新手友好度 90/100
-
难度 2/5 1-3 小时 新手友好度 70/100
huggingface/Repo2RLEnv#163 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 95/100
huggingface/sentence-transformers#4074 ·
-
comp/dashboard invalid P3
难度 2/5 1-3 小时 新手友好度 70/100
NousResearch/hermes-agent#121143 ·