failed WRONG_FIX wrong_fix · 12 tool calls · 43 s · fastapi/fastapi
🗑️ Deprecate `ORJSONResponse` and `UJSONResponse` 🗑️ Deprecate `ORJSONResponse` and `UJSONResponse` Now that there's better performance by default, with response models: https://github.com/fastapi/fastapi/pull/14962 This removes `ujson` and `orjson` from the `"fastapi[all]"` extras. To use these responses, `ujson` or `orjson` need to be explicitly installed.
| # | Tool | Arguments | Result |
|---|---|---|---|
| 1 | run_command | {
"command": "grep -rn \"ORJSONResponse\\|UJSONResponse\" fastapi/"
} | {"status": "ok", "stdout": "fastapi/responses.py:23:class UJSONResponse(JSONResponse):\nfastapi/responses.py:32: assert ujson is not None, \"ujson must be instafull{"status": "ok", "stdout": "fastapi/responses.py:23:class UJSONResponse(JSONResponse):\nfastapi/responses.py:32: assert ujson is not None, \"ujson must be installed to use UJSONResponse\"\nfastapi/responses.py:36:class ORJSONResponse(JSONResponse):\nfastapi/responses.py:45: assert orjson is not None, \"orjson must be installed to use ORJSONResponse\"\nfastapi/applications.py:369: from fastapi.responses import ORJSONResponse\nfastapi/applications.py:371: app = FastAPI(default_response_class=ORJSONResponse)\nfastapi/applications.py:1461: from fastapi.responses import ORJSONResponse\nfastapi/applications.py:1469: default_response_class=ORJSONResponse,\n", "stderr": "", "exit_code": 0} |
| 2 | read_file | {
"end_line": "50",
"filepath": "fastapi/responses.py",
"start_line": "1<|\"|>"
} | {"status": "error", "error_type": "FileReadError", "error_message": "'>' not supported between instances of 'int' and 'str'"}full{"status": "error", "error_type": "FileReadError", "error_message": "'>' not supported between instances of 'int' and 'str'"} |
| 3 | read_file | {
"end_line": "50",
"filepath": "fastapi/responses.py"
} | {"status": "error", "error_type": "FileReadError", "error_message": "'<' not supported between instances of 'int' and 'str'"}full{"status": "error", "error_type": "FileReadError", "error_message": "'<' not supported between instances of 'int' and 'str'"} |
| 4 | read_file | {
"filepath": "fastapi/responses.py"
} | {"status": "ok", "filepath": "fastapi/responses.py", "content": "from typing import Any\n\nfrom starlette.responses import FileResponse as FileResponse # noqa\nfull{"status": "ok", "filepath": "fastapi/responses.py", "content": "from typing import Any\n\nfrom starlette.responses import FileResponse as FileResponse # noqa\nfrom starlette.responses import HTMLResponse as HTMLResponse # noqa\nfrom starlette.responses import JSONResponse as JSONResponse # noqa\nfrom starlette.responses import PlainTextResponse as PlainTextResponse # noqa\nfrom starlette.responses import RedirectResponse as RedirectResponse # noqa\nfrom starlette.responses import Response as Response # noqa\nfrom starlette.responses import StreamingResponse as StreamingResponse # noqa\n\ntry:\n import ujson\nexcept ImportError: # pragma: nocover\n ujson = None # type: ignore\n\n\ntry:\n import orjson\nexcept ImportError: # pragma: nocover\n orjson = None # type: ignore\n\n\nclass UJSONResponse(JSONResponse):\n \"\"\"\n JSON response using the high-performance ujson library to serialize data to JSON.\n\n Read more about it in the\n [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).\n \"\"\"\n\n def render(self, content: Any) -> bytes:\n assert ujson is not None, \"ujson must be installed to use UJSONResponse\"\n return ujson.dumps(content, ensure_ascii=False).encode(\"utf-8\")\n\n\nclass ORJSONResponse(JSONResponse):\n \"\"\"\n JSON response using the high-performance orjson library to serialize data to JSON.\n\n Read more about it in the\n [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).\n \"\"\"\n\n def render(self, content: Any) -> bytes:\n assert orjson is not None, \"orjson must be installed to use ORJSONResponse\"\n return orjson.dumps(\n content, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY\n )", "start_line": 1, "end_line": 48, "total_lines": 48, "is_truncated": false} |
| 5 | read_file | {
"filepath": "fastapi/applications.py"
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": "from collections.abc import Awaitable, Callable, Coroutine, Sequence\nfrom enum import Enum\full{"status": "ok", "filepath": "fastapi/applications.py", "content": "from collections.abc import Awaitable, Callable, Coroutine, Sequence\nfrom enum import Enum\nfrom typing import (\n Annotated,\n Any,\n TypeVar,\n)\n\nfrom annotated_doc import Doc\nfrom fastapi import routing\nfrom fastapi.datastructures import Default, DefaultPlaceholder\nfrom fastapi.exception_handlers import (\n http_exception_handler,\n request_validation_exception_handler,\n websocket_request_validation_exception_handler,\n)\nfrom fastapi.exceptions import RequestValidationError, WebSocketRequestValidationError\nfrom fastapi.logger import logger\nfrom fastapi.middleware.asyncexitstack import AsyncExitStackMiddleware\nfrom fastapi.openapi.docs import (\n get_redoc_html,\n get_swagger_ui_html,\n get_swagger_ui_oauth2_redirect_html,\n)\nfrom fastapi.openapi.utils import get_openapi\nfrom fastapi.params import Depends\nfrom fastapi.types import DecoratedCallable, IncEx\nfrom fastapi.utils import generate_unique_id\nfrom starlette.applications import Starlette\nfrom starlette.datastructures import State\nfrom starlette.exceptions import HTTPException\nfrom starlette.middleware import Middleware\nfrom starlette.middleware.base import BaseHTTPMiddleware\nfrom starlette.middleware.errors import ServerErrorMiddleware\nfrom starlette.middleware.exceptions import ExceptionMiddleware\nfrom starlette.requests import Request\nfrom starlette.responses import HTMLResponse, JSONResponse, Response\nfrom starlette.routing import BaseRoute\nfrom starlette.types import ASGIApp, ExceptionHandler, Lifespan, Receive, Scope, Send\nfrom typing_extensions import deprecated\n\nAppType = TypeVar(\"AppType\", bound=\"FastAPI\")\n\n\nclass FastAPI(Starlette):\n \"\"\"\n `FastAPI` app class, the main entrypoint to use FastAPI.\n\n Read more in the\n [FastAPI docs for First Steps](https://fastapi.tiangolo.com/tutorial/first-steps/).\n\n ## Example\n\n ```python\n from fastapi im |
| 6 | run_command | {
"command": "grep -n \"deprecated.*ORJSONResponse\\|deprecated.*UJSONResponse\" fastapi/responses.py"
} | {"status": "error", "error_type": "CommandError", "error_message": "", "details": {"stdout": "", "stderr": "", "exit_code": 1}}full{"status": "error", "error_type": "CommandError", "error_message": "", "details": {"stdout": "", "stderr": "", "exit_code": 1}} |
| 7 | read_file | {
"end_line": "35",
"filepath": "fastapi/responses.py",
"start_line": "20"
} | {"status": "error", "error_type": "FileReadError", "error_message": "'>' not supported between instances of 'int' and 'str'"}full{"status": "error", "error_type": "FileReadError", "error_message": "'>' not supported between instances of 'int' and 'str'"} |
| 8 | read_file | {
"end_line": "35",
"filepath": "fastapi/responses.py"
} | {"status": "error", "error_type": "FileReadError", "error_message": "'<' not supported between instances of 'int' and 'str'"}full{"status": "error", "error_type": "FileReadError", "error_message": "'<' not supported between instances of 'int' and 'str'"} |
| 9 | read_file | {
"filepath": "fastapi/responses.py"
} | {"status": "ok", "filepath": "fastapi/responses.py", "content": "from typing import Any\n\nfrom starlette.responses import FileResponse as FileResponse # noqa\nfull{"status": "ok", "filepath": "fastapi/responses.py", "content": "from typing import Any\n\nfrom starlette.responses import FileResponse as FileResponse # noqa\nfrom starlette.responses import HTMLResponse as HTMLResponse # noqa\nfrom starlette.responses import JSONResponse as JSONResponse # noqa\nfrom starlette.responses import PlainTextResponse as PlainTextResponse # noqa\nfrom starlette.responses import RedirectResponse as RedirectResponse # noqa\nfrom starlette.responses import Response as Response # noqa\nfrom starlette.responses import StreamingResponse as StreamingResponse # noqa\n\ntry:\n import ujson\nexcept ImportError: # pragma: nocover\n ujson = None # type: ignore\n\n\ntry:\n import orjson\nexcept ImportError: # pragma: nocover\n orjson = None # type: ignore\n\n\nclass UJSONResponse(JSONResponse):\n \"\"\"\n JSON response using the high-performance ujson library to serialize data to JSON.\n\n Read more about it in the\n [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).\n \"\"\"\n\n def render(self, content: Any) -> bytes:\n assert ujson is not None, \"ujson must be installed to use UJSONResponse\"\n return ujson.dumps(content, ensure_ascii=False).encode(\"utf-8\")\n\n\nclass ORJSONResponse(JSONResponse):\n \"\"\"\n JSON response using the high-performance orjson library to serialize data to JSON.\n\n Read more about it in the\n [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).\n \"\"\"\n\n def render(self, content: Any) -> bytes:\n assert orjson is not None, \"orjson must be installed to use ORJSONResponse\"\n return orjson.dumps(\n content, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY\n )", "start_line": 1, "end_line": 48, "total_lines": 48, "is_truncated": false} |
| 10 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": "from typing import Any\n\nfrom starlette.responses import FileResponse as FileResponse # noqa\nfrom starlette.responses import HTMLResponse as HTMLResponse # noqa\nfrom starlette.responses import JSONResponse as JSONResponse # noqa\nfrom starlette.responses import PlainTextResponse as PlainTextResponse # noqa\nfrom starlette.responses import RedirectResponse as RedirectResponse # noqa\nfrom starlette.responses import Response as Response # noqa\nfrom starlette.responses import StreamingResponse as StreamingResponse # noqa\nfrom typing_extensions import deprecated\n\ntry:",
"old_string": "from typing import Any\n\nfrom starlette.responses import FileResponse as FileResponse # noqa\nfrom starlette.responses import HTMLResponse as HTMLResponse # noqa\nfrom starlette.responses import JSONResponse as JSONResponse # noqa\nfrom starlette.responses import PlainTextResponse as PlainTextResponse # noqa\nfrom starlette.responses import RedirectResponse as RedirectResponse # noqa\nfrom starlette.responses import Response as Response # noqa\nfrom starlette.responses import StreamingResponse as StreamingResponse # noqa\n\ntry:"
} | {"status": "ok", "filepath": "fastapi/responses.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/responses.py\n+++ b/fastapi/responses.py\n@@ full{"status": "ok", "filepath": "fastapi/responses.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/responses.py\n+++ b/fastapi/responses.py\n@@ -7,6 +7,7 @@\n from starlette.responses import RedirectResponse as RedirectResponse # noqa\n from starlette.responses import Response as Response # noqa\n from starlette.responses import StreamingResponse as StreamingResponse # noqa\n+from typing_extensions import deprecated\n \n try:\n import ujson\n", "is_truncated": false} |
| 11 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": "@deprecated(\"Use JSONResponse instead\")\nclass UJSONResponse(JSONResponse):",
"old_string": "class UJSONResponse(JSONResponse):"
} | {"status": "ok", "filepath": "fastapi/responses.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/responses.py\n+++ b/fastapi/responses.py\n@@ full{"status": "ok", "filepath": "fastapi/responses.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/responses.py\n+++ b/fastapi/responses.py\n@@ -21,6 +21,7 @@\n orjson = None # type: ignore\n \n \n+@deprecated(\"Use JSONResponse instead\")\n class UJSONResponse(JSONResponse):\n \"\"\"\n JSON response using the high-performance ujson library to serialize data to JSON.\n", "is_truncated": false} |
| 12 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": "@deprecated(\"Use JSONResponse instead\")\nclass ORJSONResponse(JSONResponse):",
"old_string": "class ORJSONResponse(JSONResponse):"
} | {"status": "ok", "filepath": "fastapi/responses.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/responses.py\n+++ b/fastapi/responses.py\n@@ full{"status": "ok", "filepath": "fastapi/responses.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/responses.py\n+++ b/fastapi/responses.py\n@@ -35,6 +35,7 @@\n return ujson.dumps(content, ensure_ascii=False).encode(\"utf-8\")\n \n \n+@deprecated(\"Use JSONResponse instead\")\n class ORJSONResponse(JSONResponse):\n \"\"\"\n JSON response using the high-performance orjson library to serialize data to JSON.\n", "is_truncated": false} |
| 13 | submit_patch | {} | {"status": "ok", "patch_size": 1100, "files_changed": 1}full{"status": "ok", "patch_size": 1100, "files_changed": 1} |
diff --git a/fastapi/responses.py b/fastapi/responses.py
index 6c8db6f3..c330f796 100644
--- a/fastapi/responses.py
+++ b/fastapi/responses.py
@@ -7,6 +7,7 @@ from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
from starlette.responses import RedirectResponse as RedirectResponse # noqa
from starlette.responses import Response as Response # noqa
from starlette.responses import StreamingResponse as StreamingResponse # noqa
+from typing_extensions import deprecated
try:
import ujson
@@ -20,6 +21,7 @@ except ImportError: # pragma: nocover
orjson = None # type: ignore
+@deprecated("Use JSONResponse instead")
class UJSONResponse(JSONResponse):
"""
JSON response using the high-performance ujson library to serialize data to JSON.
@@ -33,6 +35,7 @@ class UJSONResponse(JSONResponse):
return ujson.dumps(content, ensure_ascii=False).encode("utf-8")
+@deprecated("Use JSONResponse instead")
class ORJSONResponse(JSONResponse):
"""
JSON response using the high-performance orjson library to serialize data to JSON.
.F
=================================== FAILURES ===================================
________________ test_orjson_response_emits_deprecation_warning ________________
def test_orjson_response_emits_deprecation_warning():
> with pytest.warns(FastAPIDeprecationWarning, match="ORJSONResponse is deprecated"):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E Failed: DID NOT WARN. No warnings of type (<class 'fastapi.exceptions.FastAPIDeprecationWarning'>,) were emitted.
E Emitted warnings: [DeprecationWarning('Use JSONResponse instead')].
tests/test_deprecated_responses.py:42: Failed
=============================== warnings summary ===============================
../../../../../../../Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/testclient.py:45
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/testclient.py:45: DeprecationWarning: The anyio.abc.BlockingPortal alias is deprecated, use anyio.from_thread.BlockingPortal instead.
_PortalFactoryType = Callable[[], AbstractContextManager[anyio.abc.BlockingPortal]]
tests/test_deprecated_responses.py::test_orjson_response_returns_correct_data
/private/tmp/swe_work/pod_step15_v1_lora/fastapi_14964/b/workspace/fastapi/routing.py:475: DeprecationWarning: Use JSONResponse instead
response = actual_response_class(content, **response_args)
tests/test_deprecated_responses.py::test_orjson_response_emits_deprecation_warning
/private/tmp/swe_work/pod_step15_v1_lora/fastapi_14964/b/workspace/tests/test_deprecated_responses.py:43: DeprecationWarning: Use JSONResponse instead
ORJSONResponse(content={"hello": "world"})
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 failed, 1 passed, 3 warnings in 0.83s