resolved RESOLVED PASS · 11 tool calls · 37 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\" fastapi/responses.py"
} | {"status": "ok", "stdout": "36:class ORJSONResponse(JSONResponse):\n45: assert orjson is not None, \"orjson must be installed to use ORJSONResponse\"\n", "exit_full{"status": "ok", "stdout": "36:class ORJSONResponse(JSONResponse):\n45: assert orjson is not None, \"orjson must be installed to use ORJSONResponse\"\n", "exit_code": 0} |
| 2 | run_command | {
"command": "grep -rn \"UJSONResponse\" fastapi/responses.py"
} | {"status": "ok", "stdout": "23:class UJSONResponse(JSONResponse):\n32: assert ujson is not None, \"ujson must be installed to use UJSONResponse\"\n", "exit_codefull{"status": "ok", "stdout": "23:class UJSONResponse(JSONResponse):\n32: assert ujson is not None, \"ujson must be installed to use UJSONResponse\"\n", "exit_code": 0} |
| 3 | read_file | {
"filepath": "fastapi/responses.py",
"start_line": 1,
"end_line": 60
} | {"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 )\n", "start_line": 1, "end_line": 48, "total_lines": 48, "is_truncated": false} |
| 4 | run_command | {
"command": "grep -rn \"deprecated\" 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}} |
| 5 | run_command | {
"command": "grep -rn \"warn\" fastapi/"
} | {"status": "ok", "stdout": "fastapi/_compat/shared.py:3:import warnings\nfastapi/_compat/shared.py:182: with warnings.catch_warnings():\nfastapi/_compat/shared.full{"status": "ok", "stdout": "fastapi/_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:130: # Pydantic >= 2.12.0 warns about field specific metadata that is unused\nfastapi/_compat/v2.py:133: # need to ignore the warning:\nfastapi/_compat/v2.py:135: from pydantic.warnings import UnsupportedFieldAttributeWarning\nfastapi/_compat/v2.py:137: warnings.simplefilter(\nfastapi/applications.py:910: logger.warning(\nfastapi/exceptions.py:254: A custom deprecation warning as DeprecationWarning is ignored\nfastapi/exceptions.py:255: Ref: https://sethmlarson.dev/deprecations-via-warnings-dont-work-for-python-libraries\nfastapi/utils.py:2:import warnings\nfastapi/utils.py:83: warnings.warn(\nfastapi/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/models.py:30: logger.warning(\nfastapi/openapi/models.py:38: logger.warning(\nfastapi/openapi/docs.py:334: level: \"warning\",\nfastapi/openapi/utils.py:4:import warnings\nfastapi/openapi/utils.py:218: warnings.warn(\nfastapi/openapi/utils.py:254: warnings.warn(message, stacklevel=1)\n", "exit_code": 0} |
| 6 | read_file | {
"end_line": 260,
"filepath": "fastapi/exceptions.py",
"start_line": 240
} | {"status": "ok", "filepath": "fastapi/exceptions.py", "content": " endpoint_ctx: EndpointContext | None = None,\n ) -> None:\n super().__init__(errors, endpointfull{"status": "ok", "filepath": "fastapi/exceptions.py", "content": " endpoint_ctx: EndpointContext | None = None,\n ) -> None:\n super().__init__(errors, endpoint_ctx=endpoint_ctx)\n self.body = body\n\n\nclass PydanticV1NotSupportedError(FastAPIError):\n \"\"\"\n A pydantic.v1 model is used, which is no longer supported.\n \"\"\"\n\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", "start_line": 240, "end_line": 256, "total_lines": 256, "is_truncated": false} |
| 7 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": "from typing import Any\n\nimport warnings\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\nfrom fastapi.exceptions import FastAPIDeprecationWarning",
"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"
} | {"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+import warnings\n \n from starlette.responses import FileResponse as FileResponse # noqa\n from starlette.responses import HTMLResponse as HTMLResponse # noqa\n@@ -7,6 +9,8 @@\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+\n+from fastapi.exceptions import FastAPIDeprecationWarning\n \n try:\n import ujson\n", "is_truncated": false} |
| 8 | 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 def render(self, content: Any) -> bytes:\n warnings.warn(\n \\\"UJSONResponse is deprecated. Use JSONResponse instead.\\\",\n 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": "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)"} |
| 9 | read_file | {
"end_line": 48,
"filepath": "fastapi/responses.py",
"start_line": 23
} | {"status": "ok", "filepath": "fastapi/responses.py", "content": "except ImportError: # pragma: nocover\n orjson = None # type: ignore\n\n\nclass UJSONResponse(Jfull{"status": "ok", "filepath": "fastapi/responses.py", "content": "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 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", "start_line": 23, "end_line": 48, "total_lines": 52, "is_truncated": false} |
| 10 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": " def render(self, content: Any) -> bytes:\n warnings.warn(\n \"UJSONResponse is deprecated. Use JSONResponse instead.\",\n 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+ 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} |
| 11 | edit_file | {
"filepath": "fastapi/responses.py",
"new_string": " def render(self, content: Any) -> bytes:\n warnings.warn(\n \"ORJSONResponse is deprecated. Use JSONResponse instead.\",\n 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+ 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} |
| 12 | submit_patch | [] | {"status": "ok", "patch_size": 1700, "files_changed": 1}full{"status": "ok", "patch_size": 1700, "files_changed": 1} |
diff --git a/fastapi/responses.py b/fastapi/responses.py
index 6c8db6f3..7a2e4376 100644
--- a/fastapi/responses.py
+++ b/fastapi/responses.py
@@ -1,5 +1,7 @@
from typing import Any
+import warnings
+
from starlette.responses import FileResponse as FileResponse # noqa
from starlette.responses import HTMLResponse as HTMLResponse # noqa
from starlette.responses import JSONResponse as JSONResponse # noqa
@@ -8,6 +10,8 @@ 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 fastapi.exceptions import FastAPIDeprecationWarning
+
try:
import ujson
except ImportError: # pragma: nocover
@@ -29,6 +33,11 @@ class UJSONResponse(JSONResponse):
"""
def render(self, content: Any) -> bytes:
+ warnings.warn(
+ "UJSONResponse is deprecated. Use JSONResponse instead.",
+ 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.",
+ 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
......... [100%]
=============================== 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]]
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
9 passed, 1 warning in 1.16s