failed WRONG_FIX wrong_fix · 16 tool calls · 99 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/responses.py"
} | {"status": "ok", "stdout": "23:class UJSONResponse(JSONResponse):\n32: assert ujson is not None, \"ujson must be installed to use UJSONResponse\"\n36:class ORJSfull{"status": "ok", "stdout": "23:class UJSONResponse(JSONResponse):\n32: assert ujson is not None, \"ujson must be installed to use UJSONResponse\"\n36:class ORJSONResponse(JSONResponse):\n45: assert orjson is not None, \"orjson must be installed to use ORJSONResponse\"\n", "exit_code": 0} |
| 2 | read_file | {
"end_line": 50,
"filepath": "fastapi/responses.py",
"start_line": 20
} | {"status": "ok", "filepath": "fastapi/responses.py", "content": " orjson = None # type: ignore\n\n\nclass UJSONResponse(JSONResponse):\n \"\"\"\n JSON response full{"status": "ok", "filepath": "fastapi/responses.py", "content": " 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 )\n", "start_line": 20, "end_line": 48, "total_lines": 48, "is_truncated": false} |
| 3 | run_command | {
"command": "grep -rn \"warning\" fastapi/responses.py"
} | {"status": "error", "error_type": "CommandError", "error_message": "Command failed with exit code 1", "details": {"stdout": "", "stderr": "", "exit_code": 1}}full{"status": "error", "error_type": "CommandError", "error_message": "Command failed with exit code 1", "details": {"stdout": "", "stderr": "", "exit_code": 1}} |
| 4 | run_command | {
"command": "grep -rn \"deprecated\" fastapi/"
} | {"status": "ok", "stdout": "fastapi/_compat/v2.py:75: \"deprecated\": None,\nfastapi/applications.py:40:from typing_extensions import deprecated\nfastapi/applicfull{"status": "ok", "stdout": "fastapi/_compat/v2.py:75: \"deprecated\": None,\nfastapi/applications.py:40:from typing_extensions import deprecated\nfastapi/applications.py:88: deprecated(\nfastapi/applications.py:635: deprecated(\nfastapi/applications.py:637: \"openapi_prefix\" has been deprecated in favor of \"root_path\", which\nfastapi/applications.py:728: deprecated: Annotated[\nfastapi/applications.py:732: Mark all *path operations* as deprecated. You probably don't need it,\nfastapi/applications.py:911: '\"openapi_prefix\" has been deprecated in favor of \"root_path\", which '\nfastapi/applications.py:973: deprecated=deprecated,\nfastapi/applications.py:1149: deprecated: bool | None = None,\nfastapi/applications.py:1177: deprecated=deprecated,\nfastapi/applications.py:1205: deprecated: bool | None = None,\nfastapi/applications.py:1234: deprecated=deprecated,\nfastapi/applications.py:1396: deprecated: Annotated[\nfastapi/applications.py:1400: Mark all the *path operations* in this router as deprecated.\nfastapi/applications.py:1415: deprecated=True,\nfastapi/applications.py:1531: deprecated=deprecated,\nfastapi/applications.py:1674: deprecated: Annotated[\nfastapi/applications.py:1678: Mark this *path operation* as deprecated.\nfastapi/applications.py:1895: deprecated=deprecated,\nfastapi/applications.py:2047: deprecated: Annotated[\nfastapi/applications.py:2051: Mark this *path operation* as deprecated.\nfastapi/applications.py:2273: deprecated=deprecated,\nfastapi/applications.py:2425: deprecated: Annotated[\nfastapi/applications.py:2429: Mark this *path operation* as deprecated.\nfastapi/applications.py:2651: deprecated=deprecated,\nfastapi/applications.py:2803: deprecated: Annot |
| 5 | read_file | {
"end_line": 25,
"filepath": "fastapi/responses.py",
"start_line": 1
} | {"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", "start_line": 1, "end_line": 25, "total_lines": 48, "is_truncated": false} |
| 6 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": "from typing import Any\n\nfrom typing_extensions import deprecated\n\nfrom starlette.responses import FileResponse as FileResponse # noqa",
"old_string": "from typing import Any\n\nfrom starlette.responses import FileResponse as FileResponse # noqa"
} | {"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@@ -1,4 +1,6 @@\n from typing import Any\n+\n+from typing_extensions import deprecated\n \n from starlette.responses import FileResponse as FileResponse # noqa\n from starlette.responses import HTMLResponse as HTMLResponse # noqa\n", "is_truncated": false} |
| 7 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": "class 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 @deprecated(\\\"UJSONResponse is deprecated. Use JSONResponse instead.\\\")\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\\\")",
"old_string": "class 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\\\")"
} | {"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"}full{"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"} |
| 8 | read_file | {
"end_line": 35,
"filepath": "fastapi/responses.py",
"start_line": 26
} | {"status": "ok", "filepath": "fastapi/responses.py", "content": " \"\"\"\n JSON response using the high-performance ujson library to serialize data to JSON.\n\nfull{"status": "ok", "filepath": "fastapi/responses.py", "content": " \"\"\"\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", "start_line": 26, "end_line": 35, "total_lines": 50, "is_truncated": false} |
| 9 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": " def render(self, content: Any) -> bytes:\n @deprecated(\"UJSONResponse is deprecated. Use JSONResponse instead.\")\n def _render():\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 return _render()",
"old_string": " 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\")"
} | {"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@@ -31,8 +31,11 @@\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+ @deprecated(\"UJSONResponse is deprecated. Use JSONResponse instead.\")\n+ def _render():\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+ return _render()\n \n \n class ORJSONResponse(JSONResponse):\n", "is_truncated": false} |
| 10 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": " 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\")",
"old_string": " def render(self, content: Any) -> bytes:\n @deprecated(\"UJSONResponse is deprecated. Use JSONResponse instead.\")\n def _render():\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 return _render()"
} | {"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@@ -31,11 +31,8 @@\n \"\"\"\n \n def render(self, content: Any) -> bytes:\n- @deprecated(\"UJSONResponse is deprecated. Use JSONResponse instead.\")\n- def _render():\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- return _render()\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 \n class ORJSONResponse(JSONResponse):\n", "is_truncated": false} |
| 11 | read_file | {
"end_line": 50,
"filepath": "fastapi/responses.py",
"start_line": 20
} | {"status": "ok", "filepath": "fastapi/responses.py", "content": " import orjson\nexcept ImportError: # pragma: nocover\n orjson = None # type: ignore\n\n\nclassfull{"status": "ok", "filepath": "fastapi/responses.py", "content": " 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 )\n", "start_line": 20, "end_line": 50, "total_lines": 50, "is_truncated": false} |
| 12 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": "@deprecated(\"UJSONResponse is deprecated. Use JSONResponse instead.\")\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 \\\"\\\"\\\"",
"old_string": "class 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 \\\"\\\"\\\""
} | {"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"}full{"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"} |
| 13 | read_file | {
"end_line": 40,
"filepath": "fastapi/responses.py",
"start_line": 25
} | {"status": "ok", "filepath": "fastapi/responses.py", "content": "class UJSONResponse(JSONResponse):\n \"\"\"\n JSON response using the high-performance ujson lifull{"status": "ok", "filepath": "fastapi/responses.py", "content": "class 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", "start_line": 25, "end_line": 40, "total_lines": 50, "is_truncated": false} |
| 14 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": "@deprecated(\"UJSONResponse is deprecated. Use JSONResponse instead.\")\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 \\\"\\\"\\\"",
"old_string": "class 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 \\\"\\\"\\\""
} | {"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"}full{"status": "error", "error_type": "FileEditError", "error_message": "old_string not found in file (tried exact, flexible and regex matching)"} |
| 15 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": "@deprecated(\"UJSONResponse is 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@@ -22,6 +22,7 @@\n orjson = None # type: ignore\n \n \n+@deprecated(\"UJSONResponse is 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} |
| 16 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": "@deprecated(\"ORJSONResponse is 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@@ -36,6 +36,7 @@\n return ujson.dumps(content, ensure_ascii=False).encode(\"utf-8\")\n \n \n+@deprecated(\"ORJSONResponse is 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} |
| 17 | submit_patch | [] | {"status": "ok", "patch_size": 1074, "files_changed": 1}full{"status": "ok", "patch_size": 1074, "files_changed": 1} |
diff --git a/fastapi/responses.py b/fastapi/responses.py
index 6c8db6f3..35590e45 100644
--- a/fastapi/responses.py
+++ b/fastapi/responses.py
@@ -1,5 +1,7 @@
from typing import Any
+from typing_extensions import deprecated
+
from starlette.responses import FileResponse as FileResponse # noqa
from starlette.responses import HTMLResponse as HTMLResponse # noqa
from starlette.responses import JSONResponse as JSONResponse # noqa
@@ -20,6 +22,7 @@ except ImportError: # pragma: nocover
orjson = None # type: ignore
+@deprecated("UJSONResponse is deprecated. Use JSONResponse instead.")
class UJSONResponse(JSONResponse):
"""
JSON response using the high-performance ujson library to serialize data to JSON.
@@ -33,6 +36,7 @@ class UJSONResponse(JSONResponse):
return ujson.dumps(content, ensure_ascii=False).encode("utf-8")
+@deprecated("ORJSONResponse is 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('ORJSONResponse is deprecated. Use JSONResponse instead.')].
tests/test_deprecated_responses.py:42: Failed
=============================== warnings summary ===============================
../../../../../../kaggle/tmp/envs/overlays/starlette-0.52.1-py3-none-any/starlette/testclient.py:45
/kaggle/tmp/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
/tmp/swe_work/eval3_submission_v2t/fastapi_14964/b/workspace/fastapi/routing.py:475: DeprecationWarning: ORJSONResponse is deprecated. Use JSONResponse instead.
response = actual_response_class(content, **response_args)
tests/test_deprecated_responses.py::test_orjson_response_emits_deprecation_warning
/tmp/swe_work/eval3_submission_v2t/fastapi_14964/b/workspace/tests/test_deprecated_responses.py:43: DeprecationWarning: ORJSONResponse is deprecated. 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 1.18s