failed WRONG_FIX UNSUBMITTED wrong_fix_unsubmitted(None) · None tool calls · 0 s · fastapi/fastapi
(not found in data/tasks.jsonl)
| # | Tool | Arguments | Result |
|---|---|---|---|
| No trace captured. | |||
--- a/fastapi/exception_handlers.py
+++ b/fastapi/exception_handlers.py
@@ -1,19 +1,19 @@
from fastapi.encoders import jsonable_encoder
from fastapi.exceptions import RequestValidationError
+from fastapi.utils import is_body_allowed_for_status_code
from starlette.exceptions import HTTPException
from starlette.requests import Request
-from starlette.responses import JSONResponse
+from starlette.responses import JSONResponse, Response
from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY
-async def http_exception_handler(request: Request, exc: HTTPException) -> JSONResponse:
+async def http_exception_handler(request: Request, exc: HTTPException) -> Response:
headers = getattr(exc, "headers", None)
- if headers:
- return JSONResponse(
- {"detail": exc.detail}, status_code=exc.status_code, headers=headers
- )
- else:
- return JSONResponse({"detail": exc.detail}, status_code=exc.status_code)
+ if not is_body_allowed_for_status_code(exc.status_code):
+ return Response(status_code=exc.status_code, headers=headers)
+ return JSONResponse(
+ {"detail": exc.detail}, status_code=exc.status_code, headers=headers
+ )
async def request_validation_exception_handler(
==================================== ERRORS ====================================
______________ ERROR collecting tests/test_starlette_exception.py ______________
ImportError while importing test module '/private/tmp/swe_work/mined_oracle/fastapi_5365/b/workspace/tests/test_starlette_exception.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/Users/jp/.local/share/uv/python/cpython-3.13.15-macos-aarch64-none/lib/python3.13/importlib/__init__.py:88: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tests/test_starlette_exception.py:1: in <module>
from fastapi import FastAPI, HTTPException
fastapi/__init__.py:7: in <module>
from .applications import FastAPI as FastAPI
fastapi/applications.py:15: in <module>
from fastapi import routing
fastapi/routing.py:21: in <module>
from fastapi import params
fastapi/params.py:4: in <module>
from pydantic.fields import FieldInfo, Undefined
E ImportError: cannot import name 'Undefined' from 'pydantic.fields' (/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/fastapi/lib/python3.13/site-packages/pydantic/fields.py)
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
1 error in 0.19s