← pod_r4_v1g

fastapi_14964

resolved RESOLVED PASS · 18 tool calls · 124 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 (19)

#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 \"warn\" 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/applications.py:910:            logger.warning(\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)\nfastapi/utils.py:2:import warnings\nfastapi/utils.py:83:    warnings.warn(\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/_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():\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": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\nimport warnings\n\np = Path(\"fastapi/responses.py\")\ns = p.read_text()\n\n# Add import warnings and FastAPIDeprecationWarning\n# We need to import warnings and FastAPIDeprecationWarning from fastapi.exceptions\n# But fastapi/responses.py is imported by many things.\n# Let's see where FastAPIDeprecationWarning is defined.\n# It's in fastapi/exceptions.py.\n# To avoid circular imports, we might need to import it inside the method.\n\n# Let's check if we can import warnings at the top.\n# The current imports are:\n# from typing import Any\n# from starlette.responses import ...\n\n# We want to add:\n# import warnings\n# from fastapi.exceptions import FastAPIDeprecationWarning\n\n# Wait, if I import FastAPIDeprecationWarning at the top of fastapi/responses.py, \n# will it cause circular imports? \n# fastapi/exceptions.py doesn't seem to import fastapi/responses.py.\n# Let's check.\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
9run_command
{
 "command": "grep -r \"from fastapi.responses import\" fastapi/exceptions.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}}
10run_command
{
 "command": "grep -r \"import fastapi.responses\" fastapi/exceptions.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}}
11run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\n\np = Path(\"fastapi/responses.py\")\ns = p.read_text()\n\n# We'll add 'import warnings' and 'from fastapi.exceptions import FastAPIDeprecationWarning'\n# But to be safe and avoid circular imports, we can import FastAPIDeprecationWarning inside the __init__ method.\n\n# Let's first add 'import warnings' at the top.\n# The first line is 'from typing import Any'\n\n# Actually, let's just add the warnings.warn inside the render method.\n# But we need FastAPIDeprecationWarning.\n\n# Let's try to add the import at the top and see if it works.\n# If it doesn't, we can move it.\n\n# Let's check where other deprecations are handled.\n# fastapi/params.py:\n# from fastapi.exceptions import FastAPIDeprecationWarning\n# ...\n# warnings.warn(\n#     \"...\",\n#     category=FastAPIDeprecationWarning,\n# )\n\n# Let's do the same in fastapi/responses.py.\n\n# First, add imports.\n# We'll add 'import warnings' and 'from fastapi.exceptions import FastAPIDeprecationWarning'\n# after 'from typing import Any'.\n\n# Let's check the current imports again.\n# from typing import Any\n# from starlette.responses import ...\n\n# Let's use a more robust way to add imports.\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
12run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/responses.py\")\ns = p.read_text()\n\n# Add imports\n# We want to add:\n# import warnings\n# from fastapi.exceptions import FastAPIDeprecationWarning\n\n# Let's find a good place.\n# The first line is 'from typing import Any'\n# We can add them after that.\n\n# However, to avoid circular imports, maybe we should import FastAPIDeprecationWarning inside the __init__ method.\n# But UJSONResponse and ORJSONResponse don't have an __init__ method defined, they inherit from JSONResponse.\n\n# Let's try to add them at the top and see.\n\n# Wait, if I add them at the top, I might introduce a circular import if fastapi.exceptions imports fastapi.responses.\n# I already checked and it doesn't.\n\n# Let's try adding them.\n# I'll add them after 'from typing import Any'.\n\n# Actually, let's just add them at the top.\n\n# Let's check the imports again.\n# from typing import Any\n#\n# from starlette.responses import ...\n\n# I'll add:\n# import warnings\n# from fastapi.exceptions import FastAPIDeprecationWarning\n\n# Let's do it.\n\n# I will use a simple replacement.\nold = \"from typing import Any\"\nnew = \"from typing import Any\\n\\nimport warnings\\nfrom fastapi.exceptions import FastAPIDeprecationWarning\"\ns = s.replace(old, new)\np.write_text(s)\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
13run_command
{
 "command": "sed -n '1,15p' fastapi/responses.py"
}
{"status": "ok", "stdout": "from typing import Any\n\nimport warnings\nfrom fastapi.exceptions import FastAPIDeprecationWarning\n\nfrom starlette.responses impo
full
{"status": "ok", "stdout": "from typing import Any\n\nimport warnings\nfrom fastapi.exceptions import FastAPIDeprecationWarning\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\n", "stderr": "", "exit_code": 0}
14run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/responses.py\")\ns = p.read_text()\n\n# Now let's add the warnings.warn in UJSONResponse.render and ORJSONResponse.render.\n\n# For UJSONResponse.render:\n# old = \"\"\"    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# new = \"\"\"    def render(self, content: Any) -> bytes:\n#         warnings.warn(\n#             \"UJSONResponse is deprecated. Use JSONResponse instead.\",\n#             category=FastAPIDeprecationWarning,\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# For ORJSONResponse.render:\n# old = \"\"\"    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# new = \"\"\"    def render(self, content: Any) -> bytes:\n#         warnings.warn(\n#             \"ORJSONResponse is deprecated. Use JSONResponse instead.\",\n#             category=FastAPIDeprecationWarning,\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#         )\"\"\"\n\n# Let's apply these.\n\n# UJSONResponse\nold_ujson = \"\"\"    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\nnew_ujson = \"\"\"    def render(self, content: Any) -> bytes:\n        warnings.warn(\n            \"UJSONResponse is deprecated. Use JSONResponse instead.\",\n            category=FastAPIDeprecationWarning,\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# ORJSONResponse\nold_orjson = \"\"\"    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\nnew_orjson = \"\"\"    def render(self, content: Any) -> bytes:\n        warnings.warn(\n            \"ORJSONResponse is deprecated. Use JSONResponse instead.\",\n            category=FastAPIDeprecationWarning,\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        )\"\"\"\n\ns = s.replace(old_ujson, new_ujson)\ns = s.replace(old_orjson, new_orjson)\np.write_text(s)\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
15run_command
{
 "command": "sed -n '20,60p' fastapi/responses.py"
}
{"status": "ok", "stdout": "try:\n import orjson\nexcept ImportError: # pragma: nocover\n orjson = None # type: ignore\n\n\nclass UJSONResponse(JSONResponse):\n
full
{"status": "ok", "stdout": "try:\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        warnings.warn(\n            \"UJSONResponse is deprecated. Use JSONResponse instead.\",\n            category=FastAPIDeprecationWarning,\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    \"\"\"\n\n    def render(self, content: Any) -> bytes:\n        warnings.warn(\n            \"ORJSONResponse is deprecated. Use JSONResponse instead.\",\n            category=FastAPIDeprecationWarning,\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        )\n", "stderr": "", "exit_code": 0}
16run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nimport warnings\nfrom fastapi.responses import UJSONResponse, ORJSONResponse\nfrom fastapi.exceptions import FastAPIDeprecationWarning\n\n# We need to mock ujson and orjson if they are not installed, \n# but they are probably installed in the environment.\n# Let's just try to instantiate and call render.\n\n# We need to catch the warning.\nwith warnings.catch_warnings(record=True) as w:\n    warnings.simplefilter(\"always\")\n    # We don't actually need to call render if we just want to see if the warning is issued.\n    # But the warning is inside render().\n    # So we need to call render().\n    \n    # Mock content\n    content = {\"message\": \"hello\"}\n    \n    # Test UJSONResponse\n    try:\n        resp = UJSONResponse(content=content)\n        resp.render(content)\n        print(f\"UJSONResponse warning: {w[-1].message}\")\n    except Exception as e:\n        print(f\"UJSONResponse error: {e}\")\n\n    # Test ORJSONResponse\n    try:\n        resp = ORJSONResponse(content=content)\n        resp.render(content)\n        print(f\"ORJSONResponse warning: {w[-1].message}\")\n    except Exception as e:\n        print(f\"ORJSONResponse error: {e}\")\nPY\n"
}
{"status": "ok", "stdout": "UJSONResponse warning: UJSONResponse is deprecated. Use JSONResponse instead.\nORJSONResponse warning: ORJSONResponse is deprecated.
full
{"status": "ok", "stdout": "UJSONResponse warning: UJSONResponse is deprecated. Use JSONResponse instead.\nORJSONResponse warning: ORJSONResponse is deprecated. Use JSONResponse instead.\n", "stderr": "", "exit_code": 0}
17run_command
{
 "command": "git diff"
}
{"status": "ok", "stdout": "diff --git a/fastapi/responses.py b/fastapi/responses.py\nindex 6c8db6f3..66ef8dbf 100644\n--- a/fastapi/responses.py\n+++ b/fastapi
full
{"status": "ok", "stdout": "diff --git a/fastapi/responses.py b/fastapi/responses.py\nindex 6c8db6f3..66ef8dbf 100644\n--- a/fastapi/responses.py\n+++ b/fastapi/responses.py\n@@ -1,5 +1,8 @@\n from typing import Any\n \n+import warnings\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 from starlette.responses import JSONResponse as JSONResponse  # noqa\n@@ -29,6 +32,10 @@ class UJSONResponse(JSONResponse):\n     \"\"\"\n \n     def render(self, content: Any) -> bytes:\n+        warnings.warn(\n+            \"UJSONResponse is deprecated. Use JSONResponse instead.\",\n+            category=FastAPIDeprecationWarning,\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@@ -42,6 +49,10 @@ class ORJSONResponse(JSONResponse):\n     \"\"\"\n \n     def render(self, content: Any) -> bytes:\n+        warnings.warn(\n+            \"ORJSONResponse is deprecated. Use JSONResponse instead.\",\n+            category=FastAPIDeprecationWarning,\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", "stderr": "", "exit_code": 0}
18run_command
{
 "command": "submit_patch"
}
{"status": "error", "error_type": "CommandError", "error_message": "/bin/bash: submit_patch: command not found\n", "details": {"stdout": "", "stderr": "/bin/bas
full
{"status": "error", "error_type": "CommandError", "error_message": "/bin/bash: submit_patch: command not found\n", "details": {"stdout": "", "stderr": "/bin/bash: submit_patch: command not found\n", "exit_code": 127}}
19submit_patch
{}
{"status": "ok", "patch_size": 1360, "files_changed": 1}
full
{"status": "ok", "patch_size": 1360, "files_changed": 1}

Patch

diff --git a/fastapi/responses.py b/fastapi/responses.py
index 6c8db6f3..66ef8dbf 100644
--- a/fastapi/responses.py
+++ b/fastapi/responses.py
@@ -1,5 +1,8 @@
 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 +32,10 @@ class UJSONResponse(JSONResponse):
     """
 
     def render(self, content: Any) -> bytes:
+        warnings.warn(
+            "UJSONResponse is deprecated. Use JSONResponse instead.",
+            category=FastAPIDeprecationWarning,
+        )
         assert ujson is not None, "ujson must be installed to use UJSONResponse"
         return ujson.dumps(content, ensure_ascii=False).encode("utf-8")
 
@@ -42,6 +49,10 @@ class ORJSONResponse(JSONResponse):
     """
 
     def render(self, content: Any) -> bytes:
+        warnings.warn(
+            "ORJSONResponse is deprecated. Use JSONResponse instead.",
+            category=FastAPIDeprecationWarning,
+        )
         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.72s