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) <noreply@anthropic.com>
This commit is contained in:
parent
dc7303875f
commit
9d2969410e
|
|
@ -4,6 +4,7 @@ import uuid
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
from starlette.responses import Response
|
||||||
|
|
||||||
from shared.exceptions import EntityNotFoundError
|
from shared.exceptions import EntityNotFoundError
|
||||||
|
|
||||||
|
|
@ -74,15 +75,16 @@ async def update_chart(
|
||||||
raise HTTPException(status_code=422, detail=str(exc))
|
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(
|
async def delete_chart(
|
||||||
chart_id: uuid.UUID,
|
chart_id: uuid.UUID,
|
||||||
repository: ChartRepository = Depends(get_chart_repository),
|
repository: ChartRepository = Depends(get_chart_repository),
|
||||||
) -> None:
|
) -> Response:
|
||||||
chart = await repository.find_by_id(chart_id)
|
chart = await repository.find_by_id(chart_id)
|
||||||
if chart is None:
|
if chart is None:
|
||||||
raise HTTPException(status_code=404, detail="Chart not found")
|
raise HTTPException(status_code=404, detail="Chart not found")
|
||||||
await repository.delete(chart_id)
|
await repository.delete(chart_id)
|
||||||
|
return Response(status_code=204)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{chart_id}/option", response_model=EChartsOptionResponse)
|
@router.get("/{chart_id}/option", response_model=EChartsOptionResponse)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import uuid
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, UploadFile, File, Query
|
from fastapi import APIRouter, Depends, HTTPException, UploadFile, File, Query
|
||||||
|
from starlette.responses import Response
|
||||||
|
|
||||||
from shared.exceptions import EntityNotFoundError, FileParsingError
|
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]}
|
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(
|
async def delete_dataset(
|
||||||
dataset_id: uuid.UUID,
|
dataset_id: uuid.UUID,
|
||||||
use_case: DeleteDataSetUseCase = Depends(get_delete_dataset_usecase),
|
use_case: DeleteDataSetUseCase = Depends(get_delete_dataset_usecase),
|
||||||
) -> None:
|
) -> Response:
|
||||||
try:
|
try:
|
||||||
await use_case.execute(dataset_id)
|
await use_case.execute(dataset_id)
|
||||||
except EntityNotFoundError:
|
except EntityNotFoundError:
|
||||||
raise HTTPException(status_code=404, detail="DataSet not found")
|
raise HTTPException(status_code=404, detail="DataSet not found")
|
||||||
|
return Response(status_code=204)
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{dataset_id}/structure")
|
@router.get("/{dataset_id}/structure")
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import uuid
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||||
|
from starlette.responses import Response
|
||||||
|
|
||||||
from shared.exceptions import EntityNotFoundError, ValidationError
|
from shared.exceptions import EntityNotFoundError, ValidationError
|
||||||
from shared.types import TemplateType
|
from shared.types import TemplateType
|
||||||
|
|
@ -120,15 +121,16 @@ async def update_template(
|
||||||
raise HTTPException(status_code=422, detail=str(e))
|
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(
|
async def delete_template(
|
||||||
template_id: uuid.UUID,
|
template_id: uuid.UUID,
|
||||||
usecase: DeleteTemplateUseCase = Depends(get_delete_template_usecase),
|
usecase: DeleteTemplateUseCase = Depends(get_delete_template_usecase),
|
||||||
) -> None:
|
) -> Response:
|
||||||
try:
|
try:
|
||||||
await usecase.execute(template_id)
|
await usecase.execute(template_id)
|
||||||
except EntityNotFoundError as e:
|
except EntityNotFoundError as e:
|
||||||
raise HTTPException(status_code=404, detail=str(e))
|
raise HTTPException(status_code=404, detail=str(e))
|
||||||
|
return Response(status_code=204)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/import", status_code=201)
|
@router.post("/import", status_code=201)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue