failed WRONG_FIX UNSUBMITTED wrong_fix_unsubmitted(None) · None tool calls · 0 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 |
|---|---|---|---|
| No trace captured. | |||
--- a/fastapi/responses.py
+++ b/fastapi/responses.py
@@ -1,12 +1,14 @@
from typing import Any
+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
from starlette.responses import PlainTextResponse as PlainTextResponse # noqa
from starlette.responses import RedirectResponse as RedirectResponse # noqa
from starlette.responses import Response as Response # noqa
from starlette.responses import StreamingResponse as StreamingResponse # noqa
+from typing_extensions import deprecated
try:
import ujson
@@ -20,25 +22,59 @@
orjson = None # type: ignore
+@deprecated(
+ "UJSONResponse is deprecated, FastAPI now serializes data directly to JSON "
+ "bytes via Pydantic when a return type or response model is set, which is "
+ "faster and doesn't need a custom response class. Read more in the FastAPI "
+ "docs: https://fastapi.tiangolo.com/advanced/custom-response/#orjson-or-response-model "
+ "and https://fastapi.tiangolo.com/tutorial/response-model/",
+ category=FastAPIDeprecationWarning,
+ stacklevel=2,
+)
class UJSONResponse(JSONResponse):
- """
- JSON response using the high-performance ujson library to serialize data to JSON.
+ """JSON response using the ujson library to serialize data to JSON.
+
+ **Deprecated**: `UJSONResponse` is deprecated. FastAPI now serializes data
+ directly to JSON bytes via Pydantic when a return type or response model is
+ set, which is faster and doesn't need a custom response class.
+
+ Read more in the
+ [FastAPI docs for Custom Response](https://fastapi.tiangolo.com/advanced/custom-response/#orjson-or-response-model)
+ and the
+ [FastAPI docs for Response Model](https://fastapi.tiangolo.com/tutorial/response-model/).
- Read more about it in the
- [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).
+ **Note**: `ujson` is not included with FastAPI and must be installed
+ separately, e.g. `pip install ujson`.
"""
def render(self, content: Any) -> bytes:
assert ujson is not None, "ujson must be installed to use UJSONResponse"
return ujson.dumps(content, ensure_ascii=False).encode("utf-8")
+@deprecated(
+ "ORJSONResponse is deprecated, FastAPI now serializes data directly to JSON "
+ "bytes via Pydantic when a return type or response model is set, which is "
+ "faster and doesn't need a custom response class. Read more in the FastAPI "
+ "docs: https://fastapi.tiangolo.com/advanced/custom-response/#orjson-or-response-model "
+ "and https://fastapi.tiangolo.com/tutorial/response-model/",
+ category=FastAPIDeprecationWarning,
+ stacklevel=2,
+)
class ORJSONResponse(JSONResponse):
- """
- JSON response using the high-performance orjson library to serialize data to JSON.
+ """JSON response using the orjson library to serialize data to JSON.
+
+ **Deprecated**: `ORJSONResponse` is deprecated. FastAPI now serializes data
+ directly to JSON bytes via Pydantic when a return type or response model is
+ set, which is faster and doesn't need a custom response class.
+
+ Read more in the
+ [FastAPI docs for Custom Response](https://fastapi.tiangolo.com/advanced/custom-response/#orjson-or-response-model)
+ and the
+ [FastAPI docs for Response Model](https://fastapi.tiangolo.com/tutorial/response-model/).
- Read more about it in the
- [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).
+ **Note**: `orjson` is not included with FastAPI and must be installed
+ separately, e.g. `pip install orjson`.
"""
def render(self, content: Any) -> bytes:nd_handling_auth
response = self._send_handling_redirects(
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/fastapi/lib/python3.13/site-packages/httpx/_client.py:979: in _send_handling_redirects
response = self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/fastapi/lib/python3.13/site-packages/httpx/_client.py:1014: in _send_single_request
response = transport.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/testclient.py:348: in handle_request
raise exc
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/testclient.py:345: in handle_request
portal.call(self.app, scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/fastapi/lib/python3.13/site-packages/anyio/from_thread.py:340: in call
return cast(T_Retval, self.start_task_soon(func, *args).result())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/jp/.local/share/uv/python/cpython-3.13.15-macos-aarch64-none/lib/python3.13/concurrent/futures/_base.py:460: in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
/Users/jp/.local/share/uv/python/cpython-3.13.15-macos-aarch64-none/lib/python3.13/concurrent/futures/_base.py:402: in __get_result
raise self._exception
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/fastapi/lib/python3.13/site-packages/anyio/from_thread.py:265: in _call_func
retval = await retval_or_awaitable
^^^^^^^^^^^^^^^^^^^^^^^^^
fastapi/applications.py:1134: in __call__
await super().__call__(scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/applications.py:107: in __call__
await self.middleware_stack(scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/middleware/errors.py:186: in __call__
raise exc
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/middleware/errors.py:164: in __call__
await self.app(scope, receive, _send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/middleware/exceptions.py:63: in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/_exception_handler.py:53: in wrapped_app
raise exc
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/_exception_handler.py:42: in wrapped_app
await app(scope, receive, sender)
fastapi/middleware/asyncexitstack.py:18: in __call__
await self.app(scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/routing.py:716: in __call__
await self.middleware_stack(scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/routing.py:736: in app
await route.handle(scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/routing.py:290: in handle
await self.app(scope, receive, send)
fastapi/routing.py:119: in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/_exception_handler.py:53: in wrapped_app
raise exc
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/_exception_handler.py:42: in wrapped_app
await app(scope, receive, sender)
fastapi/routing.py:105: in app
response = await f(request)
^^^^^^^^^^^^^^^^
fastapi/routing.py:475: in app
response = actual_response_class(content, **response_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/responses.py:189: in __init__
super().__init__(content, status_code, headers, media_type, background)
/Users/jp/repos/kaggle-gemini-coding-agent-post-training/.envs/overlays/starlette-0.52.1-py3-none-any/starlette/responses.py:46: in __init__
self.body = self.render(content)
^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <fastapi.responses.ORJSONResponse object at 0x104545160>
content = {'name': 'widget', 'price': 9.99}
def render(self, content: Any) -> bytes:
> assert orjson is not None, "orjson must be installed to use ORJSONResponse"
^^^^^^^^^^^^^^^^^^
E AssertionError: orjson must be installed to use ORJSONResponse
fastapi/responses.py:81: AssertionError
=============================== 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
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 failed, 1 warning in 1.76s