From 9d2969410e0bf59ec7faa3fa4618ae34c8562510 Mon Sep 17 00:00:00 2001 From: hailin Date: Sun, 5 Apr 2026 01:07:55 -0700 Subject: [PATCH] fix: use Response class for 204 DELETE routes FastAPI latest rejects 204 with response body. Use response_class=Response and return Response(status_code=204). Co-Authored-By: Claude Opus 4.6 (1M context) --- .../services/chart-service/src/infrastructure/api/routes.py | 6 ++++-- .../services/data-service/src/infrastructure/api/routes.py | 6 ++++-- .../template-service/src/infrastructure/api/routes.py | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/backend/services/chart-service/src/infrastructure/api/routes.py b/backend/services/chart-service/src/infrastructure/api/routes.py index ddece36..591f554 100644 --- a/backend/services/chart-service/src/infrastructure/api/routes.py +++ b/backend/services/chart-service/src/infrastructure/api/routes.py @@ -4,6 +4,7 @@ import uuid from typing import Any from fastapi import APIRouter, Depends, HTTPException +from starlette.responses import Response from shared.exceptions import EntityNotFoundError @@ -74,15 +75,16 @@ async def update_chart( raise HTTPException(status_code=422, detail=str(exc)) -@router.delete("/{chart_id}", status_code=204) +@router.delete("/{chart_id}", status_code=204, response_class=Response) async def delete_chart( chart_id: uuid.UUID, repository: ChartRepository = Depends(get_chart_repository), -) -> None: +) -> Response: chart = await repository.find_by_id(chart_id) if chart is None: raise HTTPException(status_code=404, detail="Chart not found") await repository.delete(chart_id) + return Response(status_code=204) @router.get("/{chart_id}/option", response_model=EChartsOptionResponse) diff --git a/backend/services/data-service/src/infrastructure/api/routes.py b/backend/services/data-service/src/infrastructure/api/routes.py index 2bea1cd..57533d5 100644 --- a/backend/services/data-service/src/infrastructure/api/routes.py +++ b/backend/services/data-service/src/infrastructure/api/routes.py @@ -4,6 +4,7 @@ import uuid from typing import Any from fastapi import APIRouter, Depends, HTTPException, UploadFile, File, Query +from starlette.responses import Response from shared.exceptions import EntityNotFoundError, FileParsingError @@ -93,15 +94,16 @@ async def update_row( return {"row_index": row_index, "row": dataset.raw_data[row_index]} -@router.delete("/{dataset_id}", status_code=204) +@router.delete("/{dataset_id}", status_code=204, response_class=Response) async def delete_dataset( dataset_id: uuid.UUID, use_case: DeleteDataSetUseCase = Depends(get_delete_dataset_usecase), -) -> None: +) -> Response: try: await use_case.execute(dataset_id) except EntityNotFoundError: raise HTTPException(status_code=404, detail="DataSet not found") + return Response(status_code=204) @router.get("/{dataset_id}/structure") diff --git a/backend/services/template-service/src/infrastructure/api/routes.py b/backend/services/template-service/src/infrastructure/api/routes.py index f6dff94..b1b008a 100644 --- a/backend/services/template-service/src/infrastructure/api/routes.py +++ b/backend/services/template-service/src/infrastructure/api/routes.py @@ -4,6 +4,7 @@ import uuid from typing import Any, Optional from fastapi import APIRouter, Depends, HTTPException, Query +from starlette.responses import Response from shared.exceptions import EntityNotFoundError, ValidationError from shared.types import TemplateType @@ -120,15 +121,16 @@ async def update_template( raise HTTPException(status_code=422, detail=str(e)) -@router.delete("/{template_id}", status_code=204) +@router.delete("/{template_id}", status_code=204, response_class=Response) async def delete_template( template_id: uuid.UUID, usecase: DeleteTemplateUseCase = Depends(get_delete_template_usecase), -) -> None: +) -> Response: try: await usecase.execute(template_id) except EntityNotFoundError as e: raise HTTPException(status_code=404, detail=str(e)) + return Response(status_code=204) @router.post("/import", status_code=201)