← pod_r3_v1g

fastapi_14964

failed WRONG_FIX wrong_fix · 17 tool calls · 104 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 (18)

#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/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}}
5run_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}
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 FastAPIDeprecationWarning from fastapi.exceptions\n# But fastapi/responses.py might be imported by other things that import fastapi.exceptions\n# Let's check where FastAPIDeprecationWarning is defined.\n\n# Actually, let's just use warnings.warn with FastAPIDeprecationWarning if we can import it.\n# But to avoid circular imports, maybe we should use a different way or import it inside the method.\n\n# Let's see how other deprecations are handled in FastAPI.\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
9run_command
{
 "command": "grep -rn \"warnings.warn\" fastapi | grep \"Deprecation\" | head -20"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
10run_command
{
 "command": "grep -rn \"FastAPIDeprecationWarning\" 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):\n", "stderr": "", "exit_code": 0}
11run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\n\np = Path(\"fastapi/responses.py\")\ns = p.read_text()\n\n# Add import warnings\nif \"import warnings\" not in s:\n    s = \"import warnings\\n\" + s\n\n# We should import FastAPIDeprecationWarning inside the methods to avoid circular imports\n# because fastapi.exceptions might import fastapi.responses (though it doesn't seem to now)\n# Actually, let's check if fastapi.exceptions imports fastapi.responses\n\n# Let's just add the warning in __init__ of UJSONResponse and ORJSONResponse.\n\n# For UJSONResponse\nold_ujson = \"\"\"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:\"\"\"\nnew_ujson = \"\"\"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 __init__(self, *args, **kwargs):\n        warnings.warn(\n            \"UJSONResponse is deprecated. Use JSONResponse instead.\",\n            category=DeprecationWarning,\n            stacklevel=2,\n        )\n        super().__init__(*args, **kwargs)\n\n    def render(self, content: Any) -> bytes:\"\"\"\n\n# Wait, the task says \"Deprecate ORJSONResponse and UJSONResponse\".\n# It doesn't specify the warning category. FastAPIDeprecationWarning is used elsewhere.\n# Let's use FastAPIDeprecationWarning.\n\n# But I need to import it.\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\n\np = Path(\"fastapi/responses.py\")\ns = p.read_text()\n\n# Add import warnings at the top\nif \"import warnings\" not in s:\n    # Insert after from typing import Any\n    s = s.replace(\"from typing import Any\\n\", \"from typing import Any\\nimport warnings\\n\")\n\n# For UJSONResponse\nold_ujson = \"\"\"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:\"\"\"\nnew_ujson = \"\"\"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 __init__(self, *args, **kwargs):\n        from fastapi.exceptions import FastAPIDeprecationWarning\n        warnings.warn(\n            \"UJSONResponse is deprecated. Use JSONResponse instead.\",\n            category=FastAPIDeprecationWarning,\n            stacklevel=2,\n        )\n        super().__init__(*args, **kwargs)\n\n    def render(self, content: Any) -> bytes:\"\"\"\n\ns = s.replace(old_ujson, new_ujson)\n\n# For ORJSONResponse\nold_orjson = \"\"\"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:\"\"\"\nnew_orjson = \"\"\"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 __init__(self, *args, **kwargs):\n        from fastapi.exceptions import FastAPIDeprecationWarning\n        warnings.warn(\n            \"ORJSONResponse is deprecated. Use JSONResponse instead.\",\n            category=FastAPIDeprecationWarning,\n            stacklevel=2,\n        )\n        super().__init__(*args, **kwargs)\n\n    def render(self, content: Any) -> bytes:\"\"\"\n\ns = s.replace(old_orjson, new_orjson)\n\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 '20,60p' 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 __init__(self, *args, **kwargs):\n        from fastapi.exceptions import FastAPIDeprecationWarning\n        warnings.warn(\n            \"UJSONResponse is deprecated. Use JSONResponse instead.\",\n            category=FastAPIDeprecationWarning,\n            stacklevel=2,\n        )\n        super().__init__(*args, **kwargs)\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 __init__(self, *args, **kwargs):\n        from fastapi.exceptions import FastAPIDeprecationWarning\n        warnings.warn(\n            \"ORJSONResponse is deprecated. Use JSONResponse instead.\",\n            category=FastAPIDeprecationWarning,\n            stacklevel=2,\n        )\n", "stderr": "", "exit_code": 0}
14run_command
{
 "command": "sed -n '60,80p' fastapi/responses.py"
}
{"status": "ok", "stdout": " )\n super().__init__(*args, **kwargs)\n\n def render(self, content: Any) -> bytes:\n assert orjson is not None, \"orjson must be in
full
{"status": "ok", "stdout": "        )\n        super().__init__(*args, **kwargs)\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}
15run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nimport warnings\nfrom fastapi.responses import UJSONResponse, ORJSONResponse\nimport pytest\n\ndef test_ujson_deprecation():\n    with pytest.warns(UserWarning) as record: # FastAPIDeprecationWarning inherits from UserWarning\n        UJSONResponse({\"foo\": \"bar\"})\n    assert len(record) == 1\n    assert \"UJSONResponse is deprecated\" in str(record[0].message)\n\ndef test_orjson_deprecation():\n    with pytest.warns(UserWarning) as record:\n        ORJSONResponse({\"foo\": \"bar\"})\n    assert len(record) == 1\n    assert \"ORJSONResponse is deprecated\" in str(record[0].message)\n\nif __name__ == \"__main__\":\n    try:\n        test_ujson_deprecation()\n        print(\"UJSONResponse deprecation test passed\")\n        test_orjson_deprecation()\n        print(\"ORJSONResponse deprecation test passed\")\n    except Exception as e:\n        print(f\"Test failed: {e}\")\n        raise e\nPY\n"
}
{"status": "ok", "stdout": "UJSONResponse deprecation test passed\nORJSONResponse deprecation test passed\n", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "UJSONResponse deprecation test passed\nORJSONResponse deprecation test passed\n", "stderr": "", "exit_code": 0}
16run_command
{
 "command": "git diff"
}
{"status": "ok", "stdout": "diff --git a/fastapi/responses.py b/fastapi/responses.py\nindex 6c8db6f3..c5d27153 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..c5d27153 100644\n--- a/fastapi/responses.py\n+++ b/fastapi/responses.py\n@@ -1,4 +1,5 @@\n from typing import Any\n+import warnings\n \n from starlette.responses import FileResponse as FileResponse  # noqa\n from starlette.responses import HTMLResponse as HTMLResponse  # noqa\n@@ -28,6 +29,15 @@ class UJSONResponse(JSONResponse):\n     [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).\n     \"\"\"\n \n+    def __init__(self, *args, **kwargs):\n+        from fastapi.exceptions import FastAPIDeprecationWarning\n+        warnings.warn(\n+            \"UJSONResponse is deprecated. Use JSONResponse instead.\",\n+            category=FastAPIDeprecationWarning,\n+            stacklevel=2,\n+        )\n+        super().__init__(*args, **kwargs)\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@@ -41,6 +51,15 @@ class ORJSONResponse(JSONResponse):\n     [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).\n     \"\"\"\n \n+    def __init__(self, *args, **kwargs):\n+        from fastapi.exceptions import FastAPIDeprecationWarning\n+        warnings.warn(\n+            \"ORJSONResponse is deprecated. Use JSONResponse instead.\",\n+            category=FastAPIDeprecationWarning,\n+            stacklevel=2,\n+        )\n+        super().__init__(*args, **kwargs)\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}
17run_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}}
18submit_patch
{}
{"status": "ok", "patch_size": 1758, "files_changed": 1}
full
{"status": "ok", "patch_size": 1758, "files_changed": 1}

Patch

diff --git a/fastapi/responses.py b/fastapi/responses.py
index 6c8db6f3..c5d27153 100644
--- a/fastapi/responses.py
+++ b/fastapi/responses.py
@@ -1,4 +1,5 @@
 from typing import Any
+import warnings
 
 from starlette.responses import FileResponse as FileResponse  # noqa
 from starlette.responses import HTMLResponse as HTMLResponse  # noqa
@@ -28,6 +29,15 @@ class UJSONResponse(JSONResponse):
     [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).
     """
 
+    def __init__(self, *args, **kwargs):
+        from fastapi.exceptions import FastAPIDeprecationWarning
+        warnings.warn(
+            "UJSONResponse is deprecated. Use JSONResponse instead.",
+            category=FastAPIDeprecationWarning,
+            stacklevel=2,
+        )
+        super().__init__(*args, **kwargs)
+
     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")
@@ -41,6 +51,15 @@ class ORJSONResponse(JSONResponse):
     [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).
     """
 
+    def __init__(self, *args, **kwargs):
+        from fastapi.exceptions import FastAPIDeprecationWarning
+        warnings.warn(
+            "ORJSONResponse is deprecated. Use JSONResponse instead.",
+            category=FastAPIDeprecationWarning,
+            stacklevel=2,
+        )
+        super().__init__(*args, **kwargs)
+
     def render(self, content: Any) -> bytes:
         assert orjson is not None, "orjson must be installed to use ORJSONResponse"
         return orjson.dumps(

Test output

show
r, Any]
        ],
        separate_input_output_schemas: bool = True,
    ) -> tuple[dict[str, Any], dict[str, Any], dict[str, Any]]:
        path = {}
        security_schemes: dict[str, Any] = {}
        definitions: dict[str, Any] = {}
        assert route.methods is not None, "Methods must be a list"
        if isinstance(route.response_class, DefaultPlaceholder):
            current_response_class: type[Response] = route.response_class.value
        else:
            current_response_class = route.response_class
        assert current_response_class, "A response class is needed to generate OpenAPI"
        route_response_media_type: str | None = current_response_class.media_type
        if route.include_in_schema:
            for method in route.methods:
                operation = get_openapi_operation_metadata(
                    route=route, method=method, operation_ids=operation_ids
                )
                parameters: list[dict[str, Any]] = []
                flat_dependant = get_flat_dependant(route.dependant, skip_repeats=True)
                security_definitions, operation_security = get_openapi_security_definitions(
                    flat_dependant=flat_dependant
                )
                if operation_security:
                    operation.setdefault("security", []).extend(operation_security)
                if security_definitions:
                    security_schemes.update(security_definitions)
                operation_parameters = _get_openapi_operation_parameters(
                    dependant=route.dependant,
                    model_name_map=model_name_map,
                    field_mapping=field_mapping,
                    separate_input_output_schemas=separate_input_output_schemas,
                )
                parameters.extend(operation_parameters)
                if parameters:
                    all_parameters = {
                        (param["in"], param["name"]): param for param in parameters
                    }
                    required_parameters = {
                        (param["in"], param["name"]): param
                        for param in parameters
                        if param.get("required")
                    }
                    # Make sure required definitions of the same parameter take precedence
                    # over non-required definitions
                    all_parameters.update(required_parameters)
                    operation["parameters"] = list(all_parameters.values())
                if method in METHODS_WITH_BODY:
                    request_body_oai = get_openapi_operation_request_body(
                        body_field=route.body_field,
                        model_name_map=model_name_map,
                        field_mapping=field_mapping,
                        separate_input_output_schemas=separate_input_output_schemas,
                    )
                    if request_body_oai:
                        operation["requestBody"] = request_body_oai
                if route.callbacks:
                    callbacks = {}
                    for callback in route.callbacks:
                        if isinstance(callback, routing.APIRoute):
                            (
                                cb_path,
                                cb_security_schemes,
                                cb_definitions,
                            ) = get_openapi_path(
                                route=callback,
                                operation_ids=operation_ids,
                                model_name_map=model_name_map,
                                field_mapping=field_mapping,
                                separate_input_output_schemas=separate_input_output_schemas,
                            )
                            callbacks[callback.name] = {callback.path: cb_path}
                    operation["callbacks"] = callbacks
                if route.status_code is not None:
                    status_code = str(route.status_code)
                else:
                    # It would probably make more sense for all response classes to have an
                    # explicit default status_code, and to extract it from them, instead of
                    # doing this inspection tricks, that would probably be in the future
                    # TODO: probably make status_code a default class attribute for all
                    # responses in Starlette
                    response_signature = inspect.signature(current_response_class.__init__)
                    status_code_param = response_signature.parameters.get("status_code")
                    if status_code_param is not None:
                        if isinstance(status_code_param.default, int):
                            status_code = str(status_code_param.default)
>               operation.setdefault("responses", {}).setdefault(status_code, {})[
                                                                 ^^^^^^^^^^^
                    "description"
                ] = route.response_description
E               UnboundLocalError: cannot access local variable 'status_code' where it is not associated with a value

fastapi/openapi/utils.py:355: UnboundLocalError
=============================== 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, 6 passed, 1 warning in 0.83s