โ† pod_r4_v1g

fastapi_14605

failed WRONG_FIX wrong_fix ยท 30 tool calls ยท 119 s ยท fastapi/fastapi

Task input

๐Ÿ”Š Add a custom `FastAPIDeprecationWarning`

๐Ÿ”Š Add a custom `FastAPIDeprecationWarning` and use it for deprecated logic, like Pydantic v1 models.

Motivated by: https://sethmlarson.dev/deprecations-via-warnings-dont-work-for-python-libraries

Tool calls (31)

#ToolArgumentsResult
1run_command
{
 "command": "grep -rn \"DeprecationWarning\" fastapi | head -20"
}
{"status": "ok", "stdout": "fastapi/params.py:78: category=DeprecationWarning,\nfastapi/params.py:108: category=DeprecationWarning,\nfastapi/params.py:533: cate
full
{"status": "ok", "stdout": "fastapi/params.py:78:                category=DeprecationWarning,\nfastapi/params.py:108:                category=DeprecationWarning,\nfastapi/params.py:533:                category=DeprecationWarning,\nfastapi/params.py:563:                category=DeprecationWarning,\nfastapi/dependencies/utils.py:330:                category=DeprecationWarning,\nfastapi/openapi/utils.py:220:        DeprecationWarning,\nfastapi/utils.py:200:        DeprecationWarning,\nfastapi/routing.py:643:                    category=DeprecationWarning,\nfastapi/routing.py:683:                        category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:66:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:96:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:506:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:536:                category=DeprecationWarning,\n", "stderr": "", "exit_code": 0}
2run_command
{
 "command": "ls fastapi/__init__.py fastapi/utils.py"
}
{"status": "ok", "stdout": "fastapi/__init__.py\nfastapi/utils.py\n", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "fastapi/__init__.py\nfastapi/utils.py\n", "stderr": "", "exit_code": 0}
3run_command
{
 "command": "cat fastapi/__init__.py"
}
{"status": "ok", "stdout": "\"\"\"FastAPI framework, high performance, easy to learn, fast to code, ready for production\"\"\"\n\n__version__ = \"0.127.0\"\n\nf
full
{"status": "ok", "stdout": "\"\"\"FastAPI framework, high performance, easy to learn, fast to code, ready for production\"\"\"\n\n__version__ = \"0.127.0\"\n\nfrom starlette import status as status\n\nfrom .applications import FastAPI as FastAPI\nfrom .background import BackgroundTasks as BackgroundTasks\nfrom .datastructures import UploadFile as UploadFile\nfrom .exceptions import HTTPException as HTTPException\nfrom .exceptions import WebSocketException as WebSocketException\nfrom .param_functions import Body as Body\nfrom .param_functions import Cookie as Cookie\nfrom .param_functions import Depends as Depends\nfrom .param_functions import File as File\nfrom .param_functions import Form as Form\nfrom .param_functions import Header as Header\nfrom .param_functions import Path as Path\nfrom .param_functions import Query as Query\nfrom .param_functions import Security as Security\nfrom .requests import Request as Request\nfrom .responses import Response as Response\nfrom .routing import APIRouter as APIRouter\nfrom .websockets import WebSocket as WebSocket\nfrom .websockets import WebSocketDisconnect as WebSocketDisconnect\n", "stderr": "", "exit_code": 0}
4run_command
{
 "command": "cat fastapi/utils.py"
}
{"status": "ok", "stdout": "import re\nimport warnings\nfrom collections.abc import MutableMapping\nfrom typing import (\n TYPE_CHECKING,\n Any,\n Optional,\n U
full
{"status": "ok", "stdout": "import re\nimport warnings\nfrom collections.abc import MutableMapping\nfrom typing import (\n    TYPE_CHECKING,\n    Any,\n    Optional,\n    Union,\n    cast,\n)\nfrom weakref import WeakKeyDictionary\n\nimport fastapi\nfrom fastapi._compat import (\n    BaseConfig,\n    ModelField,\n    PydanticSchemaGenerationError,\n    Undefined,\n    UndefinedType,\n    Validator,\n    annotation_is_pydantic_v1,\n    lenient_issubclass,\n    may_v1,\n)\nfrom fastapi.datastructures import DefaultPlaceholder, DefaultType\nfrom pydantic import BaseModel\nfrom pydantic.fields import FieldInfo\nfrom typing_extensions import Literal\n\nfrom ._compat import v2\n\nif TYPE_CHECKING:  # pragma: nocover\n    from .routing import APIRoute\n\n# Cache for `create_cloned_field`\n_CLONED_TYPES_CACHE: MutableMapping[type[BaseModel], type[BaseModel]] = (\n    WeakKeyDictionary()\n)\n\n\ndef is_body_allowed_for_status_code(status_code: Union[int, str, None]) -> bool:\n    if status_code is None:\n        return True\n    # Ref: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#patterned-fields-1\n    if status_code in {\n        \"default\",\n        \"1XX\",\n        \"2XX\",\n        \"3XX\",\n        \"4XX\",\n        \"5XX\",\n    }:\n        return True\n    current_status_code = int(status_code)\n    return not (current_status_code < 200 or current_status_code in {204, 205, 304})\n\n\ndef get_path_param_names(path: str) -> set[str]:\n    return set(re.findall(\"{(.*?)}\", path))\n\n\n_invalid_args_message = (\n    \"Invalid args for response field! Hint: \"\n    \"check that {type_} is a valid Pydantic field type. \"\n    \"If you are using a return type annotation that is not a valid Pydantic \"\n    \"field (e.g. Union[Response, dict, None]) you can disable generating the \"\n    \"response model from the type annotation with the path operation decorator \"\n    \"parameter response_model=None. Read more: \"\n    \"https://fastapi.tiang
5run_command
{
 "command": "grep -rn \"DeprecationWarning\" fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "stdout": "fastapi/temp_pydantic_v1_params.py:66: category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:96: category=DeprecationWarn
full
{"status": "ok", "stdout": "fastapi/temp_pydantic_v1_params.py:66:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:96:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:506:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:536:                category=DeprecationWarning,\n", "stderr": "", "exit_code": 0}
6run_command
{
 "command": "cat fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "stdout": "import warnings\nfrom typing import Annotated, Any, Callable, Optional, Union\n\nfrom fastapi.openapi.models import Example\nfrom fa
full
{"status": "ok", "stdout": "import warnings\nfrom typing import Annotated, Any, Callable, Optional, Union\n\nfrom fastapi.openapi.models import Example\nfrom fastapi.params import ParamTypes\nfrom typing_extensions import deprecated\n\nfrom ._compat.may_v1 import FieldInfo, Undefined\n\n_Unset: Any = Undefined\n\n\nclass Param(FieldInfo):\n    in_: ParamTypes\n\n    def __init__(\n        self,\n        default: Any = Undefined,\n        *,\n        default_factory: Union[Callable[[], Any], None] = _Unset,\n        annotation: Optional[Any] = None,\n        alias: Optional[str] = None,\n        alias_priority: Union[int, None] = _Unset,\n        # TODO: update when deprecating Pydantic v1, import these types\n        # validation_alias: str | AliasPath | AliasChoices | None\n        validation_alias: Union[str, None] = None,\n        serialization_alias: Union[str, None] = None,\n        title: Optional[str] = None,\n        description: Optional[str] = None,\n        gt: Optional[float] = None,\n        ge: Optional[float] = None,\n        lt: Optional[float] = None,\n        le: Optional[float] = None,\n        min_length: Optional[int] = None,\n        max_length: Optional[int] = None,\n        pattern: Optional[str] = None,\n        regex: Annotated[\n            Optional[str],\n            deprecated(\n                \"Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead.\"\n            ),\n        ] = None,\n        discriminator: Union[str, None] = None,\n        strict: Union[bool, None] = _Unset,\n        multiple_of: Union[float, None] = _Unset,\n        allow_inf_nan: Union[bool, None] = _Unset,\n        max_digits: Union[int, None] = _Unset,\n        decimal_places: Union[int, None] = _Unset,\n        examples: Optional[list[Any]] = None,\n        example: Annotated[\n            Optional[Any],\n            deprecated(\n                \"Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, \"\n                \"although still s
7run_command
{
 "command": "grep -rn \"DeprecationWarning\" fastapi/params.py fastapi/dependencies/utils.py fastapi/openapi/utils.py fastapi/routing.py"
}
{"status": "ok", "stdout": "fastapi/params.py:78: category=DeprecationWarning,\nfastapi/params.py:108: category=DeprecationWarning,\nfastapi/params.py:533: cate
full
{"status": "ok", "stdout": "fastapi/params.py:78:                category=DeprecationWarning,\nfastapi/params.py:108:                category=DeprecationWarning,\nfastapi/params.py:533:                category=DeprecationWarning,\nfastapi/params.py:563:                category=DeprecationWarning,\nfastapi/dependencies/utils.py:330:                category=DeprecationWarning,\nfastapi/openapi/utils.py:220:        DeprecationWarning,\nfastapi/routing.py:643:                    category=DeprecationWarning,\nfastapi/routing.py:683:                        category=DeprecationWarning,\n", "stderr": "", "exit_code": 0}
8run_command
{
 "command": "cat fastapi/exceptions.py"
}
{"status": "ok", "stdout": "from collections.abc import Sequence\nfrom typing import Annotated, Any, Optional, TypedDict, Union\n\nfrom annotated_doc import Doc
full
{"status": "ok", "stdout": "from collections.abc import Sequence\nfrom typing import Annotated, Any, Optional, TypedDict, Union\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    function: str\n    path: str\n    file: str\n    line: int\n\n\nclass HTTPException(StarletteHTTPException):\n    \"\"\"\n    An HTTP exception you can raise in your own code to show errors to the client.\n\n    This is for client errors, invalid authentication, invalid data, etc. Not for server\n    errors in your code.\n\n    Read more about it in the\n    [FastAPI docs for Handling Errors](https://fastapi.tiangolo.com/tutorial/handling-errors/).\n\n    ## Example\n\n    ```python\n    from fastapi import FastAPI, HTTPException\n\n    app = FastAPI()\n\n    items = {\"foo\": \"The Foo Wrestlers\"}\n\n\n    @app.get(\"/items/{item_id}\")\n    async def read_item(item_id: str):\n        if item_id not in items:\n            raise HTTPException(status_code=404, detail=\"Item not found\")\n        return {\"item\": items[item_id]}\n    ```\n    \"\"\"\n\n    def __init__(\n        self,\n        status_code: Annotated[\n            int,\n            Doc(\n                \"\"\"\n                HTTP status code to send to the client.\n                \"\"\"\n            ),\n        ],\n        detail: Annotated[\n            Any,\n            Doc(\n                \"\"\"\n                Any data to be sent to the client in the `detail` key of the JSON\n                response.\n                \"\"\"\n            ),\n        ] = None,\n        headers: Annotated[\n            Optional[dict[str, str]],\n            Doc(\n                \"\"\"\n                Any headers to send to the client in the response.\n                \"\"\"\n            ),\n  
9run_command
{
 "command": "cat fastapi/exceptions.py | tail -n 20"
}
{"status": "ok", "stdout": "class WebSocketRequestValidationError(ValidationException):\n def __init__(\n self,\n errors: Sequence[Any],\n *,\n endpoint_ctx: Op
full
{"status": "ok", "stdout": "class WebSocketRequestValidationError(ValidationException):\n    def __init__(\n        self,\n        errors: Sequence[Any],\n        *,\n        endpoint_ctx: Optional[EndpointContext] = None,\n    ) -> None:\n        super().__init__(errors, endpoint_ctx=endpoint_ctx)\n\n\nclass ResponseValidationError(ValidationException):\n    def __init__(\n        self,\n        errors: Sequence[Any],\n        *,\n        body: Any = None,\n        endpoint_ctx: Optional[EndpointContext] = None,\n    ) -> None:\n        super().__init__(errors, endpoint_ctx=endpoint_ctx)\n        self.body = body\n", "stderr": "", "exit_code": 0}
10run_command
{
 "command": "cat fastapi/utils.py | head -n 20"
}
{"status": "ok", "stdout": "import re\nimport warnings\nfrom collections.abc import MutableMapping\nfrom typing import (\n TYPE_CHECKING,\n Any,\n Optional,\n U
full
{"status": "ok", "stdout": "import re\nimport warnings\nfrom collections.abc import MutableMapping\nfrom typing import (\n    TYPE_CHECKING,\n    Any,\n    Optional,\n    Union,\n    cast,\n)\nfrom weakref import WeakKeyDictionary\n\nimport fastapi\nfrom fastapi._compat import (\n    BaseConfig,\n    ModelField,\n    PydanticSchemaGenerationError,\n    Undefined,\n    UndefinedType,\n    Validator,\n", "stderr": "", "exit_code": 0}
11run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/utils.py\")\ns = p.read_text()\nold = 'import warnings'\nnew = 'import warnings\\n\\nclass FastAPIDeprecationWarning(DeprecationWarning):\\n    pass'\n# This is wrong because DeprecationWarning is a built-in, but I should check where to put it.\n# Actually, the task says \"Add a custom FastAPIDeprecationWarning\".\n# Usually, such warnings are defined in a central place.\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/utils.py\")\ns = p.read_text()\nold = 'import warnings'\nnew = 'import warnings\\n\\nclass FastAPIDeprecationWarning(DeprecationWarning):\\n    pass'\n# Wait, I should check if it's better in fastapi/exceptions.py or fastapi/utils.py.\n# DeprecationWarning is not an exception in the sense of being raised, but it is a warning.\n# Looking at other projects, they often put custom warnings in a `warnings.py` or `exceptions.py` or `utils.py`.\n# In FastAPI, `fastapi/utils.py` seems like a reasonable place if there isn't a better one.\n# But let's check if there's a `fastapi/warnings.py`.\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
13run_command
{
 "command": "ls fastapi/warnings.py"
}
{"status": "error", "error_type": "CommandError", "error_message": "ls: fastapi/warnings.py: No such file or directory\n", "details": {"stdout": "", "stderr": "
full
{"status": "error", "error_type": "CommandError", "error_message": "ls: fastapi/warnings.py: No such file or directory\n", "details": {"stdout": "", "stderr": "ls: fastapi/warnings.py: No such file or directory\n", "exit_code": 1}}
14run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/utils.py\")\ns = p.read_text()\nold = 'import warnings'\nnew = 'import warnings\\n\\nclass FastAPIDeprecationWarning(DeprecationWarning):\\n    pass'\np.write_text(s.replace(old, new))\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
15run_command
{
 "command": "grep -rn \"category=DeprecationWarning\" fastapi | head -20"
}
{"status": "ok", "stdout": "fastapi/params.py:78: category=DeprecationWarning,\nfastapi/params.py:108: category=DeprecationWarning,\nfastapi/params.py:533: cate
full
{"status": "ok", "stdout": "fastapi/params.py:78:                category=DeprecationWarning,\nfastapi/params.py:108:                category=DeprecationWarning,\nfastapi/params.py:533:                category=DeprecationWarning,\nfastapi/params.py:563:                category=DeprecationWarning,\nfastapi/dependencies/utils.py:330:                category=DeprecationWarning,\nfastapi/routing.py:643:                    category=DeprecationWarning,\nfastapi/routing.py:683:                        category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:66:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:96:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:506:                category=DeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:536:                category=DeprecationWarning,\n", "stderr": "", "exit_code": 0}
16run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nimport re\nfrom pathlib import Path\n\nfiles_to_fix = [\n    \"fastapi/params.py\",\n    \"fastapi/dependencies/utils.py\",\n    \"fastapi/routing.py\",\n    \"fastapi/temp_pydantic_v1_params.py\",\n]\n\nfor file_path in files_to_fix:\n    p = Path(file_path)\n    if not p.exists():\n        continue\n    s = p.read_text()\n    if \"category=DeprecationWarning\" in s:\n        # We need to import FastAPIDeprecationWarning.\n        # It's in fastapi.utils.\n        if \"from fastapi.utils import FastAPIDeprecationWarning\" not in s:\n            # Add import. We'll add it at the top.\n            # Find where other fastapi imports are.\n            if \"import fastapi\" in s:\n                s = s.replace(\"import fastapi\", \"import fastapi\\nfrom fastapi.utils import FastAPIDeprecationWarning\")\n            elif \"from fastapi\" in s:\n                # Find the first 'from fastapi' and add it after.\n                # This is a bit risky. Let's just add it at the top.\n                s = \"from fastapi.utils import FastAPIDeprecationWarning\\n\" + s\n            else:\n                s = \"from fastapi.utils import FastAPIDeprecationWarning\\n\" + s\n        \n        s = s.replace(\"category=DeprecationWarning\", \"category=FastAPIDeprecationWarning\")\n        p.write_text(s)\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
17run_command
{
 "command": "grep -rn \"category=FastAPIDeprecationWarning\" fastapi | head -20"
}
{"status": "ok", "stdout": "fastapi/params.py:79: category=FastAPIDeprecationWarning,\nfastapi/params.py:109: category=FastAPIDeprecationWarning,\nfastapi/param
full
{"status": "ok", "stdout": "fastapi/params.py:79:                category=FastAPIDeprecationWarning,\nfastapi/params.py:109:                category=FastAPIDeprecationWarning,\nfastapi/params.py:534:                category=FastAPIDeprecationWarning,\nfastapi/params.py:564:                category=FastAPIDeprecationWarning,\nfastapi/dependencies/utils.py:331:                category=FastAPIDeprecationWarning,\nfastapi/routing.py:644:                    category=FastAPIDeprecationWarning,\nfastapi/routing.py:684:                        category=FastAPIDeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:67:                category=FastAPIDeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:97:                category=FastAPIDeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:507:                category=FastAPIDeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:537:                category=FastAPIDeprecationWarning,\n", "stderr": "", "exit_code": 0}
18run_command
{
 "command": "grep -rn \"DeprecationWarning\" fastapi | grep -v \"FastAPIDeprecationWarning\""
}
{"status": "ok", "stdout": "fastapi/openapi/utils.py:220: DeprecationWarning,\nfastapi/utils.py:203: DeprecationWarning,\n", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "fastapi/openapi/utils.py:220:        DeprecationWarning,\nfastapi/utils.py:203:        DeprecationWarning,\n", "stderr": "", "exit_code": 0}
19run_command
{
 "command": "cat fastapi/openapi/utils.py | sed -n '210,230p'"
}
{"status": "ok", "stdout": " request_body_oai[\"content\"] = {request_media_type: request_media_content}\n return request_body_oai\n\n\ndef generate_operation_i
full
{"status": "ok", "stdout": "    request_body_oai[\"content\"] = {request_media_type: request_media_content}\n    return request_body_oai\n\n\ndef generate_operation_id(\n    *, route: routing.APIRoute, method: str\n) -> str:  # pragma: nocover\n    warnings.warn(\n        \"fastapi.openapi.utils.generate_operation_id() was deprecated, \"\n        \"it is not used internally, and will be removed soon\",\n        DeprecationWarning,\n        stacklevel=2,\n    )\n    if route.operation_id:\n        return route.operation_id\n    path: str = route.path_format\n    return generate_operation_id_for_path(name=route.name, path=path, method=method)\n\n\ndef generate_operation_summary(*, route: routing.APIRoute, method: str) -> str:\n    if route.summary:\n", "stderr": "", "exit_code": 0}
20run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/openapi/utils.py\")\ns = p.read_text()\nold = '        DeprecationWarning,'\nnew = '        FastAPIDeprecationWarning,'\nif old in s:\n    if \"from fastapi.utils import FastAPIDeprecationWarning\" not in s:\n        # Add import\n        s = \"from fastapi.utils import FastAPIDeprecationWarning\\n\" + s\n    p.write_text(s.replace(old, new))\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
21run_command
{
 "command": "cat fastapi/utils.py | sed -n '190,210p'"
}
{"status": "ok", "stdout": " new_field.post_validators = field.post_validators # type: ignore[attr-defined]\n new_field.parse_json = field.parse_json # type: ig
full
{"status": "ok", "stdout": "    new_field.post_validators = field.post_validators  # type: ignore[attr-defined]\n    new_field.parse_json = field.parse_json  # type: ignore[attr-defined]\n    new_field.shape = field.shape  # type: ignore[attr-defined]\n    new_field.populate_validators()  # type: ignore[attr-defined]\n    return new_field\n\n\ndef generate_operation_id_for_path(\n    *, name: str, path: str, method: str\n) -> str:  # pragma: nocover\n    warnings.warn(\n        \"fastapi.utils.generate_operation_id_for_path() was deprecated, \"\n        \"it is not used internally, and will be removed soon\",\n        DeprecationWarning,\n        stacklevel=2,\n    )\n    operation_id = f\"{name}{path}\"\n    operation_id = re.sub(r\"\\W\", \"_\", operation_id)\n    operation_id = f\"{operation_id}_{method.lower()}\"\n    return operation_id\n\n", "stderr": "", "exit_code": 0}
22run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/utils.py\")\ns = p.read_text()\nold = '        DeprecationWarning,'\nnew = '        FastAPIDeprecationWarning,'\np.write_text(s.replace(old, new))\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
23run_command
{
 "command": "grep -rn \"DeprecationWarning\" fastapi | grep -v \"FastAPIDeprecationWarning\""
}
{"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}}
24run_command
{
 "command": "grep -rn \"FastAPIDeprecationWarning\" fastapi | head -20"
}
{"status": "ok", "stdout": "fastapi/params.py:1:from fastapi.utils import FastAPIDeprecationWarning\nfastapi/params.py:79: category=FastAPIDeprecationWarning,\n
full
{"status": "ok", "stdout": "fastapi/params.py:1:from fastapi.utils import FastAPIDeprecationWarning\nfastapi/params.py:79:                category=FastAPIDeprecationWarning,\nfastapi/params.py:109:                category=FastAPIDeprecationWarning,\nfastapi/params.py:534:                category=FastAPIDeprecationWarning,\nfastapi/params.py:564:                category=FastAPIDeprecationWarning,\nfastapi/dependencies/utils.py:1:from fastapi.utils import FastAPIDeprecationWarning\nfastapi/dependencies/utils.py:331:                category=FastAPIDeprecationWarning,\nfastapi/openapi/utils.py:1:from fastapi.utils import FastAPIDeprecationWarning\nfastapi/openapi/utils.py:221:        FastAPIDeprecationWarning,\nfastapi/utils.py:4:class FastAPIDeprecationWarning(DeprecationWarning):\nfastapi/utils.py:203:        FastAPIDeprecationWarning,\nfastapi/routing.py:1:from fastapi.utils import FastAPIDeprecationWarning\nfastapi/routing.py:644:                    category=FastAPIDeprecationWarning,\nfastapi/routing.py:684:                        category=FastAPIDeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:1:from fastapi.utils import FastAPIDeprecationWarning\nfastapi/temp_pydantic_v1_params.py:67:                category=FastAPIDeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:97:                category=FastAPIDeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:507:                category=FastAPIDeprecationWarning,\nfastapi/temp_pydantic_v1_params.py:537:                category=FastAPIDeprecationWarning,\n", "stderr": "", "exit_code": 0}
25run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/params.py\")\ns = p.read_text()\nif s.startswith(\"from fastapi.utils import FastAPIDeprecationWarning\\n\"):\n    # Try to move it to a better place, e.g., after other imports.\n    # For now, let's just check if it works.\n    pass\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
26run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/params.py\")\ns = p.read_text()\n# Move the import from the top to a more appropriate place if needed.\n# But the current state is functional.\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
27run_command
{
 "command": "git diff"
}
{"status": "ok", "stdout": "diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py\nindex 39d0bd89..d375bed1 100644\n--- a/fastapi/dependenc
full
{"status": "ok", "stdout": "diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py\nindex 39d0bd89..d375bed1 100644\n--- a/fastapi/dependencies/utils.py\n+++ b/fastapi/dependencies/utils.py\n@@ -1,3 +1,4 @@\n+from fastapi.utils import FastAPIDeprecationWarning\n import dataclasses\n import inspect\n import sys\n@@ -327,7 +328,7 @@ def get_dependant(\n             warnings.warn(\n                 \"pydantic.v1 is deprecated and will soon stop being supported by FastAPI.\"\n                 f\" Please update the param {param_name}: {param_details.type_annotation!r}.\",\n-                category=DeprecationWarning,\n+                category=FastAPIDeprecationWarning,\n                 stacklevel=5,\n             )\n         if isinstance(\ndiff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py\nindex a99d4188..49b57e65 100644\n--- a/fastapi/openapi/utils.py\n+++ b/fastapi/openapi/utils.py\n@@ -1,3 +1,4 @@\n+from fastapi.utils import FastAPIDeprecationWarning\n import http.client\n import inspect\n import warnings\n@@ -217,7 +218,7 @@ def generate_operation_id(\n     warnings.warn(\n         \"fastapi.openapi.utils.generate_operation_id() was deprecated, \"\n         \"it is not used internally, and will be removed soon\",\n-        DeprecationWarning,\n+        FastAPIDeprecationWarning,\n         stacklevel=2,\n     )\n     if route.operation_id:\ndiff --git a/fastapi/params.py b/fastapi/params.py\nindex c776c4a5..93930f9b 100644\n--- a/fastapi/params.py\n+++ b/fastapi/params.py\n@@ -1,3 +1,4 @@\n+from fastapi.utils import FastAPIDeprecationWarning\n import warnings\n from collections.abc import Sequence\n from dataclasses import dataclass\n@@ -75,7 +76,7 @@ class Param(FieldInfo):  # type: ignore[misc]\n         if example is not _Unset:\n             warnings.warn(\n                 \"`example` has been deprecated, please use `examples` instead\",\n-                category=DeprecationWarning,\n+                category=FastAPIDepreca
28run_command
{
 "command": "cd /workspace && python3 - <<'PY'\nfrom pathlib import Path\np = Path(\"fastapi/utils.py\")\ns = p.read_text()\nold = 'import warnings\\n\\nclass FastAPIDeprecationWarning(DeprecationWarning):\\n    pass'\n# Let's make sure it's not duplicated.\nif s.count(old) > 1:\n    p.write_text(s.replace(old + '\\n' + old, old))\nPY\n"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
29run_command
{
 "command": "cat fastapi/utils.py | head -n 10"
}
{"status": "ok", "stdout": "import re\nimport warnings\n\nclass FastAPIDeprecationWarning(DeprecationWarning):\n pass\nfrom collections.abc import MutableMappin
full
{"status": "ok", "stdout": "import re\nimport warnings\n\nclass FastAPIDeprecationWarning(DeprecationWarning):\n    pass\nfrom collections.abc import MutableMapping\nfrom typing import (\n    TYPE_CHECKING,\n    Any,\n    Optional,\n", "stderr": "", "exit_code": 0}
30run_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}}
31submit_patch
{}
{"status": "ok", "patch_size": 6963, "files_changed": 6}
full
{"status": "ok", "patch_size": 6963, "files_changed": 6}

Patch

diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py
index 39d0bd89..d375bed1 100644
--- a/fastapi/dependencies/utils.py
+++ b/fastapi/dependencies/utils.py
@@ -1,3 +1,4 @@
+from fastapi.utils import FastAPIDeprecationWarning
 import dataclasses
 import inspect
 import sys
@@ -327,7 +328,7 @@ def get_dependant(
             warnings.warn(
                 "pydantic.v1 is deprecated and will soon stop being supported by FastAPI."
                 f" Please update the param {param_name}: {param_details.type_annotation!r}.",
-                category=DeprecationWarning,
+                category=FastAPIDeprecationWarning,
                 stacklevel=5,
             )
         if isinstance(
diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py
index a99d4188..49b57e65 100644
--- a/fastapi/openapi/utils.py
+++ b/fastapi/openapi/utils.py
@@ -1,3 +1,4 @@
+from fastapi.utils import FastAPIDeprecationWarning
 import http.client
 import inspect
 import warnings
@@ -217,7 +218,7 @@ def generate_operation_id(
     warnings.warn(
         "fastapi.openapi.utils.generate_operation_id() was deprecated, "
         "it is not used internally, and will be removed soon",
-        DeprecationWarning,
+        FastAPIDeprecationWarning,
         stacklevel=2,
     )
     if route.operation_id:
diff --git a/fastapi/params.py b/fastapi/params.py
index c776c4a5..93930f9b 100644
--- a/fastapi/params.py
+++ b/fastapi/params.py
@@ -1,3 +1,4 @@
+from fastapi.utils import FastAPIDeprecationWarning
 import warnings
 from collections.abc import Sequence
 from dataclasses import dataclass
@@ -75,7 +76,7 @@ class Param(FieldInfo):  # type: ignore[misc]
         if example is not _Unset:
             warnings.warn(
                 "`example` has been deprecated, please use `examples` instead",
-                category=DeprecationWarning,
+                category=FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         self.example = example
@@ -105,7 +106,7 @@ class Param(FieldInfo):  # type: ignore[misc]
         if regex is not None:
             warnings.warn(
                 "`regex` has been deprecated, please use `pattern` instead",
-                category=DeprecationWarning,
+                category=FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         current_json_schema_extra = json_schema_extra or extra
@@ -530,7 +531,7 @@ class Body(FieldInfo):  # type: ignore[misc]
         if example is not _Unset:
             warnings.warn(
                 "`example` has been deprecated, please use `examples` instead",
-                category=DeprecationWarning,
+                category=FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         self.example = example
@@ -560,7 +561,7 @@ class Body(FieldInfo):  # type: ignore[misc]
         if regex is not None:
             warnings.warn(
                 "`regex` has been deprecated, please use `pattern` instead",
-                category=DeprecationWarning,
+                category=FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         current_json_schema_extra = json_schema_extra or extra
diff --git a/fastapi/routing.py b/fastapi/routing.py
index 2770e325..1fe561dc 100644
--- a/fastapi/routing.py
+++ b/fastapi/routing.py
@@ -1,3 +1,4 @@
+from fastapi.utils import FastAPIDeprecationWarning
 import email.message
 import functools
 import inspect
@@ -640,7 +641,7 @@ class APIRoute(routing.Route):
                 warnings.warn(
                     "pydantic.v1 is deprecated and will soon stop being supported by FastAPI."
                     f" Please update the response model {self.response_model!r}.",
-                    category=DeprecationWarning,
+                    category=FastAPIDeprecationWarning,
                     stacklevel=4,
                 )
             self.response_field = create_model_field(
@@ -680,7 +681,7 @@ class APIRoute(routing.Route):
                     warnings.warn(
                         "pydantic.v1 is deprecated and will soon stop being supported by FastAPI."
                         f" In responses={{}}, please update {model}.",
-                        category=DeprecationWarning,
+                        category=FastAPIDeprecationWarning,
                         stacklevel=4,
                     )
                 response_field = create_model_field(
diff --git a/fastapi/temp_pydantic_v1_params.py b/fastapi/temp_pydantic_v1_params.py
index 1bda0ea9..c4d5f02b 100644
--- a/fastapi/temp_pydantic_v1_params.py
+++ b/fastapi/temp_pydantic_v1_params.py
@@ -1,3 +1,4 @@
+from fastapi.utils import FastAPIDeprecationWarning
 import warnings
 from typing import Annotated, Any, Callable, Optional, Union
 
@@ -63,7 +64,7 @@ class Param(FieldInfo):
         if example is not _Unset:
             warnings.warn(
                 "`example` has been deprecated, please use `examples` instead",
-                category=DeprecationWarning,
+                category=FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         self.example = example
@@ -93,7 +94,7 @@ class Param(FieldInfo):
         if regex is not None:
             warnings.warn(
                 "`regex` has been deprecated, please use `pattern` instead",
-                category=DeprecationWarning,
+                category=FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         current_json_schema_extra = json_schema_extra or extra
@@ -503,7 +504,7 @@ class Body(FieldInfo):
         if example is not _Unset:
             warnings.warn(
                 "`example` has been deprecated, please use `examples` instead",
-                category=DeprecationWarning,
+                category=FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         self.example = example
@@ -533,7 +534,7 @@ class Body(FieldInfo):
         if regex is not None:
             warnings.warn(
                 "`regex` has been deprecated, please use `pattern` instead",
-                category=DeprecationWarning,
+                category=FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         current_json_schema_extra = json_schema_extra or extra
diff --git a/fastapi/utils.py b/fastapi/utils.py
index c4631d7e..17e1b915 100644
--- a/fastapi/utils.py
+++ b/fastapi/utils.py
@@ -1,5 +1,8 @@
 import re
 import warnings
+
+class FastAPIDeprecationWarning(DeprecationWarning):
+    pass
 from collections.abc import MutableMapping
 from typing import (
     TYPE_CHECKING,
@@ -197,7 +200,7 @@ def generate_operation_id_for_path(
     warnings.warn(
         "fastapi.utils.generate_operation_id_for_path() was deprecated, "
         "it is not used internally, and will be removed soon",
-        DeprecationWarning,
+        FastAPIDeprecationWarning,
         stacklevel=2,
     )
     operation_id = f"{name}{path}"

Test output

show
==================================== ERRORS ====================================
________ ERROR collecting tests/benchmarks/test_general_performance.py _________
ImportError while importing test module '/private/tmp/swe_work/pod_r4_v1g/fastapi_14605/b/workspace/tests/benchmarks/test_general_performance.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/Users/jp/.local/share/uv/python/cpython-3.13.15-macos-aarch64-none/lib/python3.13/importlib/__init__.py:88: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tests/benchmarks/test_general_performance.py:9: in <module>
    from fastapi.exceptions import FastAPIDeprecationWarning
E   ImportError: cannot import name 'FastAPIDeprecationWarning' from 'fastapi.exceptions' (/private/tmp/swe_work/pod_r4_v1g/fastapi_14605/b/workspace/fastapi/exceptions.py)
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 error in 0.38s