← pod_r1_v1n

fastapi_14964

resolved RESOLVED UNSUBMITTED PASS · 34 tool calls · 310 s · fastapi/fastapi

Task input

🗑️ 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 calls (34)

#ToolArgumentsResult
1run_command
{
 "command": "grep -rn \"ORJSONResponse\" fastapi | head -20"
}
{"status": "ok", "stdout": "fastapi/responses.py:36:class ORJSONResponse(JSONResponse):\nfastapi/responses.py:45: assert orjson is not None, \"orjson must be in
full
{"status": "ok", "stdout": "fastapi/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}
2run_command
{
 "command": "grep -rn \"UJSONResponse\" fastapi | head -20"
}
{"status": "ok", "stdout": "fastapi/responses.py:23:class UJSONResponse(JSONResponse):\nfastapi/responses.py:32: assert ujson is not None, \"ujson must be insta
full
{"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\"\n", "stderr": "", "exit_code": 0}
3run_command
{
 "command": "sed -n '20,50p' fastapi/responses.py"
}
{"status": "ok", "stdout": " orjson = None # type: ignore\n\n\nclass UJSONResponse(JSONResponse):\n \"\"\"\n JSON response using the high-performance ujson libr
full
{"status": "ok", "stdout": "    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", "stderr": "", "exit_code": 0}
4run_command
{
 "command": "grep -rn \"warnings\" fastapi | head -20"
}
{"status": "ok", "stdout": "fastapi/params.py:1:import warnings\nfastapi/params.py:76: warnings.warn(\nfastapi/params.py:106: warnings.warn(\nfastapi/params.py:
full
{"status": "ok", "stdout": "fastapi/params.py:1:import warnings\nfastapi/params.py:76:            warnings.warn(\nfastapi/params.py:106:            warnings.warn(\nfastapi/params.py:521:            warnings.warn(\nfastapi/params.py:551:            warnings.warn(\nfastapi/openapi/utils.py:4:import warnings\nfastapi/openapi/utils.py:218:    warnings.warn(\nfastapi/openapi/utils.py:254:        warnings.warn(message, stacklevel=1)\nfastapi/utils.py:2:import warnings\nfastapi/utils.py:83:    warnings.warn(\nfastapi/exceptions.py:255:    Ref: https://sethmlarson.dev/deprecations-via-warnings-dont-work-for-python-libraries\nfastapi/_compat/shared.py:3:import warnings\nfastapi/_compat/shared.py:182:        with warnings.catch_warnings():\nfastapi/_compat/shared.py:183:            warnings.simplefilter(\"ignore\", UserWarning)\nfastapi/_compat/shared.py:194:        with warnings.catch_warnings():\nfastapi/_compat/shared.py:195:            warnings.simplefilter(\"ignore\", UserWarning)\nfastapi/_compat/v2.py:2:import warnings\nfastapi/_compat/v2.py:129:        with warnings.catch_warnings():\nfastapi/_compat/v2.py:135:                from pydantic.warnings import UnsupportedFieldAttributeWarning\nfastapi/_compat/v2.py:137:                warnings.simplefilter(\n", "stderr": "", "exit_code": 0}
5run_command
{
 "command": "grep -rn \"DeprecationWarning\" fastapi | head -20"
}
{"status": "ok", "stdout": "fastapi/params.py:7:from fastapi.exceptions import FastAPIDeprecationWarning\nfastapi/params.py:78: category=FastAPIDeprecationWarni
full
{"status": "ok", "stdout": "fastapi/params.py:7:from fastapi.exceptions import FastAPIDeprecationWarning\nfastapi/params.py:78:                category=FastAPIDeprecationWarning,\nfastapi/params.py:108:                category=FastAPIDeprecationWarning,\nfastapi/params.py:523:                category=FastAPIDeprecationWarning,\nfastapi/params.py:553:                category=FastAPIDeprecationWarning,\nfastapi/openapi/utils.py:27:from fastapi.exceptions import FastAPIDeprecationWarning\nfastapi/openapi/utils.py:221:        category=FastAPIDeprecationWarning,\nfastapi/utils.py:17:from fastapi.exceptions import FastAPIDeprecationWarning, PydanticV1NotSupportedError\nfastapi/utils.py:86:        category=FastAPIDeprecationWarning,\nfastapi/exceptions.py:252:class FastAPIDeprecationWarning(UserWarning):\nfastapi/exceptions.py:254:    A custom deprecation warning as DeprecationWarning is ignored\n", "stderr": "", "exit_code": 0}
6run_command
{
 "command": "sed -n '250,260p' fastapi/exceptions.py"
}
{"status": "ok", "stdout": "\n\nclass FastAPIDeprecationWarning(UserWarning):\n \"\"\"\n A custom deprecation warning as DeprecationWarning is ignored\n Ref: ht
full
{"status": "ok", "stdout": "\n\nclass FastAPIDeprecationWarning(UserWarning):\n    \"\"\"\n    A custom deprecation warning as DeprecationWarning is ignored\n    Ref: https://sethmlarson.dev/deprecations-via-warnings-dont-work-for-python-libraries\n    \"\"\"\n", "stderr": "", "exit_code": 0}
7run_command
{
 "command": "sed -n '1,30p' fastapi/responses.py"
}
{"status": "ok", "stdout": "from typing import Any\n\nfrom starlette.responses import FileResponse as FileResponse # noqa\nfrom starlette.responses import HTMLR
full
{"status": "ok", "stdout": "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", "stderr": "", "exit_code": 0}
8run_command
{
 "command": "sed -n '1,10p' fastapi/exceptions.py"
}
{"status": "ok", "stdout": "from collections.abc import Mapping, Sequence\nfrom typing import Annotated, Any, TypedDict\n\nfrom annotated_doc import Doc\nfrom p
full
{"status": "ok", "stdout": "from collections.abc import Mapping, Sequence\nfrom typing import Annotated, Any, TypedDict\n\nfrom annotated_doc import Doc\nfrom pydantic import BaseModel, create_model\nfrom starlette.exceptions import HTTPException as StarletteHTTPException\nfrom starlette.exceptions import WebSocketException as StarletteWebSocketException\n\n\nclass EndpointContext(TypedDict, total=False):\n", "stderr": "", "exit_code": 0}
9run_command
{
 "command": "sed -n '20,40p' fastapi/responses.py"
}
{"status": "ok", "stdout": " orjson = None # type: ignore\n\n\nclass UJSONResponse(JSONResponse):\n \"\"\"\n JSON response using the high-performance ujson libr
full
{"status": "ok", "stdout": "    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", "stderr": "", "exit_code": 0}
10run_command
{
 "command": "sed -n '30,50p' fastapi/responses.py"
}
{"status": "ok", "stdout": "\n def render(self, content: Any) -> bytes:\n assert ujson is not None, \"ujson must be installed to use UJSONResponse\"\n return uj
full
{"status": "ok", "stdout": "\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", "stderr": "", "exit_code": 0}
11run_command
{
 "command": "grep -n \"import warnings\" 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}}
12run_command
{
 "command": "grep -n \"from fastapi.exceptions import FastAPIDeprecationWarning\" 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}}
13run_command
{
 "command": "sed -n '1,20p' fastapi/responses.py"
}
{"status": "ok", "stdout": "from typing import Any\n\nfrom starlette.responses import FileResponse as FileResponse # noqa\nfrom starlette.responses import HTMLR
full
{"status": "ok", "stdout": "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", "stderr": "", "exit_code": 0}
14run_command
{
 "command": "edit_file filepath=\"fastapi/responses.py\" old_string=\"from typing import Any\" new_string=\"from typing import Any\n\nimport warnings\n\nfrom fastapi.exceptions import FastAPIDeprecationWarning\""
}
{"status": "error", "error_type": "CommandError", "error_message": "/bin/bash: edit_file: command not found\n", "details": {"stdout": "", "stderr": "/bin/bash:
full
{"status": "error", "error_type": "CommandError", "error_message": "/bin/bash: edit_file: command not found\n", "details": {"stdout": "", "stderr": "/bin/bash: edit_file: command not found\n", "exit_code": 127}}
15edit_file
{
 "filepath": "fastapi/responses.py",
 "new_string": "from typing import Any\n\nimport warnings\n\nfrom fastapi.exceptions import FastAPIDeprecationWarning\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,8 @@\n from typing import Any\n+\n+import warnings\n+\n+from fastapi.exceptions import FastAPIDeprecationWarning\n \n from starlette.responses import FileResponse as FileResponse  # noqa\n from starlette.responses import HTMLResponse as HTMLResponse  # noqa\n", "is_truncated": false}
16edit_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    .. deprecated:: 0.111.0\n       Use `JSONResponse` instead.\n    \\\"\\\"\\\"\n\n    def render(self, content: Any) -> bytes:\n        warnings.warn(\n            \\\"UJSONResponse is deprecated. Use JSONResponse instead.\\\",\n            category=FastAPIDeprecationWarning,\n            stacklevel=2,\n        )\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": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and
full
{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context."}
17run_command
{
 "command": "sed -n '23,35p' fastapi/responses.py"
}
{"status": "ok", "stdout": "except ImportError: # pragma: nocover\n orjson = None # type: ignore\n\n\nclass UJSONResponse(JSONResponse):\n \"\"\"\n JSON respons
full
{"status": "ok", "stdout": "except 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", "stderr": "", "exit_code": 0}
18run_command
{
 "command": "sed -n '35,42p' fastapi/responses.py"
}
{"status": "ok", "stdout": " def render(self, content: Any) -> bytes:\n assert ujson is not None, \"ujson must be installed to use UJSONResponse\"\n return ujso
full
{"status": "ok", "stdout": "    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", "stderr": "", "exit_code": 0}
19edit_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    .. deprecated:: 0.111.0\n       Use `JSONResponse` instead.\n    \\\"\\\"\\\"\n\n    def render(self, content: Any) -> bytes:\n        warnings.warn(\n            \\\"UJSONResponse is deprecated. Use JSONResponse instead.\\\",\n            category=FastAPIDeprecationWarning,\n            stacklevel=2,\n        )\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": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and
full
{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context."}
20run_command
{
 "command": "cat -n fastapi/responses.py | sed -n '23,42p'"
}
{"status": "ok", "stdout": " 23\texcept ImportError: # pragma: nocover\n 24\t orjson = None # type: ignore\n 25\t\n 26\t\n 27\tclass UJSONResponse(JSONResponse)
full
{"status": "ok", "stdout": "    23\texcept ImportError:  # pragma: nocover\n    24\t    orjson = None  # type: ignore\n    25\t\n    26\t\n    27\tclass UJSONResponse(JSONResponse):\n    28\t    \"\"\"\n    29\t    JSON response using the high-performance ujson library to serialize data to JSON.\n    30\t\n    31\t    Read more about it in the\n    32\t    [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).\n    33\t    \"\"\"\n    34\t\n    35\t    def render(self, content: Any) -> bytes:\n    36\t        assert ujson is not None, \"ujson must be installed to use UJSONResponse\"\n    37\t        return ujson.dumps(content, ensure_ascii=False).encode(\"utf-8\")\n    38\t\n    39\t\n    40\tclass ORJSONResponse(JSONResponse):\n    41\t    \"\"\"\n    42\t    JSON response using the high-performance orjson library to serialize data to JSON.\n", "stderr": "", "exit_code": 0}
21edit_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    .. deprecated:: 0.111.0\n       Use `JSONResponse` instead.\n    \\\"\\\"\\\"\n\n    def render(self, content: Any) -> bytes:\n        warnings.warn(\n            \\\"UJSONResponse is deprecated. Use JSONResponse instead.\\\",\n            category=FastAPIDeprecationWarning,\n            stacklevel=2,\n        )\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": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and
full
{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context."}
22edit_file
{
 "filepath": "fastapi/responses.py",
 "new_string": "    def render(self, content: Any) -> bytes:\n        warnings.warn(\n            \"UJSONResponse is deprecated. Use JSONResponse instead.\",\n            category=FastAPIDeprecationWarning,\n            stacklevel=2,\n        )\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        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@@ -33,6 +33,11 @@\n     \"\"\"\n \n     def render(self, content: Any) -> bytes:\n+        warnings.warn(\n+            \"UJSONResponse is deprecated. Use JSONResponse instead.\",\n+            category=FastAPIDeprecationWarning,\n+            stacklevel=2,\n+        )\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", "is_truncated": false}
23edit_file
{
 "filepath": "fastapi/responses.py",
 "new_string": "    \\\"\\\"\\\"\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    .. deprecated:: 0.111.0\n       Use `JSONResponse` instead.\n    \\\"\\\"\\\"",
 "old_string": "    \\\"\\\"\\\"\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": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and
full
{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context."}
24run_command
{
 "command": "sed -n '27,33p' fastapi/responses.py"
}
{"status": "ok", "stdout": "class UJSONResponse(JSONResponse):\n \"\"\"\n JSON response using the high-performance ujson library to serialize data to JSON.\n\n
full
{"status": "ok", "stdout": "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", "stderr": "", "exit_code": 0}
25edit_file
{
 "filepath": "fastapi/responses.py",
 "new_string": "    \\\"\\\"\\\"\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    .. deprecated:: 0.111.0\n       Use `JSONResponse` instead.\n    \\\"\\\"\\\"",
 "old_string": "    \\\"\\\"\\\"\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": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and
full
{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context."}
26run_command
{
 "command": "cat -n fastapi/responses.py | sed -n '27,33p'"
}
{"status": "ok", "stdout": " 27\tclass UJSONResponse(JSONResponse):\n 28\t \"\"\"\n 29\t JSON response using the high-performance ujson library to serialize dat
full
{"status": "ok", "stdout": "    27\tclass UJSONResponse(JSONResponse):\n    28\t    \"\"\"\n    29\t    JSON response using the high-performance ujson library to serialize data to JSON.\n    30\t\n    31\t    Read more about it in the\n    32\t    [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).\n    33\t    \"\"\"\n", "stderr": "", "exit_code": 0}
27edit_file
{
 "filepath": "fastapi/responses.py",
 "new_string": "    \\\"\\\"\\\"\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    .. deprecated:: 0.111.0\n       Use `JSONResponse` instead.\n    \\\"\\\"\\\"",
 "old_string": "    \\\"\\\"\\\"\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": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and
full
{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context."}
28run_command
{
 "command": "sed -n '36,50p' fastapi/responses.py"
}
{"status": "ok", "stdout": " warnings.warn(\n \"UJSONResponse is deprecated. Use JSONResponse instead.\",\n category=FastAPIDeprecationWarning,\n stacklevel=2,\
full
{"status": "ok", "stdout": "        warnings.warn(\n            \"UJSONResponse is deprecated. Use JSONResponse instead.\",\n            category=FastAPIDeprecationWarning,\n            stacklevel=2,\n        )\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", "stderr": "", "exit_code": 0}
29run_command
{
 "command": "sed -n '45,55p' fastapi/responses.py"
}
{"status": "ok", "stdout": "class ORJSONResponse(JSONResponse):\n \"\"\"\n JSON response using the high-performance orjson library to serialize data to JSON.\n\
full
{"status": "ok", "stdout": "class 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", "stderr": "", "exit_code": 0}
30edit_file
{
 "filepath": "fastapi/responses.py",
 "new_string": "    def render(self, content: Any) -> bytes:\n        warnings.warn(\n            \"ORJSONResponse is deprecated. Use JSONResponse instead.\",\n            category=FastAPIDeprecationWarning,\n            stacklevel=2,\n        )\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        )",
 "old_string": "    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        )"
}
{"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@@ -51,6 +51,11 @@\n     \"\"\"\n \n     def render(self, content: Any) -> bytes:\n+        warnings.warn(\n+            \"ORJSONResponse is deprecated. Use JSONResponse instead.\",\n+            category=FastAPIDeprecationWarning,\n+            stacklevel=2,\n+        )\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", "is_truncated": false}
31edit_file
{
 "filepath": "fastapi/responses.py",
 "new_string": "    \\\"\\\"\\\"\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    .. deprecated:: 0.111.0\n       Use `JSONResponse` instead.\n    \\\"\\\"\\\"",
 "old_string": "    \\\"\\\"\\\"\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    \\\"\\\"\\\""
}
{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and
full
{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context."}
32run_command
{
 "command": "cat -n fastapi/responses.py | sed -n '40,50p'"
}
{"status": "ok", "stdout": " 40\t )\n 41\t assert ujson is not None, \"ujson must be installed to use UJSONResponse\"\n 42\t return ujson.dumps(content, ensure_
full
{"status": "ok", "stdout": "    40\t        )\n    41\t        assert ujson is not None, \"ujson must be installed to use UJSONResponse\"\n    42\t        return ujson.dumps(content, ensure_ascii=False).encode(\"utf-8\")\n    43\t\n    44\t\n    45\tclass ORJSONResponse(JSONResponse):\n    46\t    \"\"\"\n    47\t    JSON response using the high-performance orjson library to serialize data to JSON.\n    48\t\n    49\t    Read more about it in the\n    50\t    [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).\n", "stderr": "", "exit_code": 0}
33run_command
{
 "command": "cat -n fastapi/responses.py | sed -n '50,55p'"
}
{"status": "ok", "stdout": " 50\t [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).\n 51\
full
{"status": "ok", "stdout": "    50\t    [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).\n    51\t    \"\"\"\n    52\t\n    53\t    def render(self, content: Any) -> bytes:\n    54\t        warnings.warn(\n    55\t            \"ORJSONResponse is deprecated. Use JSONResponse instead.\",\n", "stderr": "", "exit_code": 0}
34edit_file
{
 "filepath": "fastapi/responses.py",
 "new_string": "    \\\"\\\"\\\"\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    .. deprecated:: 0.111.0\n       Use `JSONResponse` instead.\n    \\\"\\\"\\\"",
 "old_string": "    \\\"\\\"\\\"\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    \\\"\\\"\\\""
}
{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and
full
{"status": "error", "error_type": "FileEditError", "error_message": "Failed to replace: old_string not found. Ensure you're not escaping content incorrectly and check whitespace, indentation, and context."}

Patch

diff --git a/fastapi/responses.py b/fastapi/responses.py
index 6c8db6f3..6907b5f2 100644
--- a/fastapi/responses.py
+++ b/fastapi/responses.py
@@ -1,5 +1,9 @@
 from typing import Any
 
+import warnings
+
+from fastapi.exceptions import FastAPIDeprecationWarning
+
 from starlette.responses import FileResponse as FileResponse  # noqa
 from starlette.responses import HTMLResponse as HTMLResponse  # noqa
 from starlette.responses import JSONResponse as JSONResponse  # noqa
@@ -29,6 +33,11 @@ class UJSONResponse(JSONResponse):
     """
 
     def render(self, content: Any) -> bytes:
+        warnings.warn(
+            "UJSONResponse is deprecated. Use JSONResponse instead.",
+            category=FastAPIDeprecationWarning,
+            stacklevel=2,
+        )
         assert ujson is not None, "ujson must be installed to use UJSONResponse"
         return ujson.dumps(content, ensure_ascii=False).encode("utf-8")
 
@@ -42,6 +51,11 @@ class ORJSONResponse(JSONResponse):
     """
 
     def render(self, content: Any) -> bytes:
+        warnings.warn(
+            "ORJSONResponse is deprecated. Use JSONResponse instead.",
+            category=FastAPIDeprecationWarning,
+            stacklevel=2,
+        )
         assert orjson is not None, "orjson must be installed to use ORJSONResponse"
         return orjson.dumps(
             content, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY

Test output

show
.........                                                                [100%]
=============================== 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]]

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
9 passed, 1 warning in 0.74s