hotfix: 修复 204 状态码 response_class=Response 导致 API 容器崩溃 #177

Merged
xiaoxia merged 1 commits from hotfix/fix-204-response-class into main 2026-07-02 21:03:18 +08:00
Owner

紧急热修复

v0.1.103 部署后 API 容器崩溃重启,根因:多个路由的 @router.delete 同时设置了 status_code=204 和 response_class=Response,FastAPI 不允许 204 有响应体。

修复内容

移除 8 处 response_class=Response

  • duplication.py:242
  • recipes.py:177
  • templates.py:198, 276
  • titles.py:146
  • tts.py:179
  • voice_clones.py:194
  • voices.py:319
## 紧急热修复 v0.1.103 部署后 API 容器崩溃重启,根因:多个路由的 @router.delete 同时设置了 status_code=204 和 response_class=Response,FastAPI 不允许 204 有响应体。 ### 修复内容 移除 8 处 `response_class=Response`: - duplication.py:242 - recipes.py:177 - templates.py:198, 276 - titles.py:146 - tts.py:179 - voice_clones.py:194 - voices.py:319
xiaoxia added 1 commit 2026-07-02 20:56:14 +08:00
hotfix: 移除 delete 路由的 response_class=Response 修复 204 断言崩溃
Tests / lint (pull_request) Failing after 159h56m48s
Tests / test (pull_request) Failing after 159h56m48s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 159h57m21s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 159h57m26s
CI/CD Pipeline / Frontend Lint (push) Failing after 159h58m2s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 159h58m8s
dd2808d17a
FastAPI 不允许 status_code=204 同时指定 response_class=Response,
导致 API 容器启动时 AssertionError 不断重启。

修复 8 处 @router.delete 装饰器:
- duplication.py:242
- recipes.py:177
- templates.py:198, 276
- titles.py:146
- tts.py:179
- voice_clones.py:194
- voices.py:319
Author
Owner

代码审计通过 — 可立即合并

审计范围:7 个路由文件,8 处 @router.delete 修改

验证结果

全部 8 处 response_class=Response 已正确移除,与指令完全一致:

文件 行号 修改 状态
duplication.py L242 status_code=204, response_class=Responsestatus_code=204
recipes.py L177 同上
templates.py L198 同上
templates.py L276 同上
titles.py L146 同上
tts.py L179 同上
voice_clones.py L194 同上(多行格式)
voices.py L319 同上

补充说明

Response 仍保留在 import 中且用于 return Response(status_code=204) — 这是 FastAPI 标准做法,显式返回 Response 对象不会触发 AssertionError,原始问题仅出在装饰器的 response_class 参数上。无需额外清理。

结论:0 P0 / 0 P1 / 0 P2,修改精准无遗漏,建议立即合并到 main 恢复线上服务。

## ✅ 代码审计通过 — 可立即合并 **审计范围**:7 个路由文件,8 处 `@router.delete` 修改 ### 验证结果 全部 8 处 `response_class=Response` 已正确移除,与指令完全一致: | 文件 | 行号 | 修改 | 状态 | |------|------|------|------| | duplication.py | L242 | `status_code=204, response_class=Response` → `status_code=204` | ✅ | | recipes.py | L177 | 同上 | ✅ | | templates.py | L198 | 同上 | ✅ | | templates.py | L276 | 同上 | ✅ | | titles.py | L146 | 同上 | ✅ | | tts.py | L179 | 同上 | ✅ | | voice_clones.py | L194 | 同上(多行格式) | ✅ | | voices.py | L319 | 同上 | ✅ | ### 补充说明 `Response` 仍保留在 import 中且用于 `return Response(status_code=204)` — 这是 FastAPI 标准做法,显式返回 `Response` 对象不会触发 `AssertionError`,原始问题仅出在装饰器的 `response_class` 参数上。无需额外清理。 **结论**:0 P0 / 0 P1 / 0 P2,修改精准无遗漏,建议立即合并到 main 恢复线上服务。
xiaoxia merged commit d0e4235828 into main 2026-07-02 21:03:18 +08:00
Sign in to join this conversation.