โ† pod_r1_v1n

fastapi_14605

failed WRONG_FIX wrong_fix ยท 28 tool calls ยท 121 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 (29)

#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": "grep -rn \"Pydantic v1\" fastapi | head -20"
}
{"status": "ok", "stdout": "fastapi/params.py:36: # TODO: update when deprecating Pydantic v1, import these types\nfastapi/params.py:149: # TODO: update when de
full
{"status": "ok", "stdout": "fastapi/params.py:36:        # TODO: update when deprecating Pydantic v1, import these types\nfastapi/params.py:149:        # TODO: update when deprecating Pydantic v1, import these types\nfastapi/params.py:235:        # TODO: update when deprecating Pydantic v1, import these types\nfastapi/params.py:319:        # TODO: update when deprecating Pydantic v1, import these types\nfastapi/params.py:405:        # TODO: update when deprecating Pydantic v1, import these types\nfastapi/params.py:489:        # TODO: update when deprecating Pydantic v1, import these types\nfastapi/params.py:602:        # TODO: update when deprecating Pydantic v1, import these types\nfastapi/params.py:686:        # TODO: update when deprecating Pydantic v1, import these types\nfastapi/dependencies/utils.py:552:                    # For Pydantic v1\nfastapi/encoders.py:31:# Taken from Pydantic v1 as is\nfastapi/encoders.py:36:# Adapted from Pydantic v1\nfastapi/encoders.py:228:        # TODO: remove when deprecating Pydantic v1\nfastapi/encoders.py:250:            # TODO: remove when deprecating Pydantic v1\nfastapi/openapi/models.py:146:    # TODO: uncomment and remove below when deprecating Pydantic v1\nfastapi/utils.py:124:    # Pydantic v2 is not installed, but it's not a Pydantic v1 ModelField, it could be\nfastapi/utils.py:125:    # a Pydantic v1 type, like a constrained int\nfastapi/routing.py:658:            # TODO: remove when deprecating Pydantic v1\nfastapi/temp_pydantic_v1_params.py:24:        # TODO: update when deprecating Pydantic v1, import these types\nfastapi/temp_pydantic_v1_params.py:122:        # TODO: update when deprecating Pydantic v1, import these types\nfastapi/temp_pydantic_v1_params.py:208:        # TODO: update when deprecating Pydantic v1, import these types\n", "stderr": "", "exit_code": 0}
4run_command
{
 "command": "cat fastapi/utils.py | head -n 100"
}
{"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 -n \"DeprecationWarning\" fastapi/params.py fastapi/dependencies/utils.py fastapi/openapi/utils.py fastapi/routing.py fastapi/temp_pydantic_v1_params.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,\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}
6run_command
{
 "command": "grep -n \"DeprecationWarning\" fastapi/utils.py"
}
{"status": "ok", "stdout": "200: DeprecationWarning,\n", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "200:        DeprecationWarning,\n", "stderr": "", "exit_code": 0}
7run_command
{
 "command": "sed -n '190,210p' fastapi/utils.py"
}
{"status": "ok", "stdout": " new_field.populate_validators() # type: ignore[attr-defined]\n return new_field\n\n\ndef generate_operation_id_for_path(\n *, name:
full
{"status": "ok", "stdout": "    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\ndef generate_unique_id(route: \"APIRoute\") -> str:\n    operation_id = f\"{route.name}{route.path_format}\"\n", "stderr": "", "exit_code": 0}
8edit_file
{
 "filepath": "fastapi/utils.py",
 "new_string": "class FastAPIDeprecationWarning(DeprecationWarning):\n    pass\n\n\ndef is_body_allowed_for_status_code(status_code: Union[int, str, None]) -> bool:",
 "old_string": "def is_body_allowed_for_status_code(status_code: Union[int, str, None]) -> bool:"
}
{"status": "ok", "filepath": "fastapi/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/utils.py\n+++ b/fastapi/utils.py\n@@ -36,6 +36,10
full
{"status": "ok", "filepath": "fastapi/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/utils.py\n+++ b/fastapi/utils.py\n@@ -36,6 +36,10 @@\n _CLONED_TYPES_CACHE: MutableMapping[type[BaseModel], type[BaseModel]] = (\n     WeakKeyDictionary()\n )\n+\n+\n+class FastAPIDeprecationWarning(DeprecationWarning):\n+    pass\n \n \n def is_body_allowed_for_status_code(status_code: Union[int, str, None]) -> bool:\n", "is_truncated": false}
9run_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}
10run_command
{
 "command": "grep -rn \"DeprecationWarning\" fastapi | grep -v \"category=DeprecationWarning\" | head -20"
}
{"status": "ok", "stdout": "fastapi/openapi/utils.py:220: DeprecationWarning,\nfastapi/utils.py:41:class FastAPIDeprecationWarning(DeprecationWarning):\nfastapi
full
{"status": "ok", "stdout": "fastapi/openapi/utils.py:220:        DeprecationWarning,\nfastapi/utils.py:41:class FastAPIDeprecationWarning(DeprecationWarning):\nfastapi/utils.py:204:        DeprecationWarning,\n", "stderr": "", "exit_code": 0}
11run_command
{
 "command": "sed -n '215,225p' fastapi/openapi/utils.py"
}
{"status": "ok", "stdout": " *, route: routing.APIRoute, method: str\n) -> str: # pragma: nocover\n warnings.warn(\n \"fastapi.openapi.utils.generate_operation_
full
{"status": "ok", "stdout": "    *, 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", "stderr": "", "exit_code": 0}
12run_command
{
 "command": "sed -n '195,210p' fastapi/utils.py"
}
{"status": "ok", "stdout": " return new_field\n\n\ndef generate_operation_id_for_path(\n *, name: str, path: str, method: str\n) -> str: # pragma: nocover\n war
full
{"status": "ok", "stdout": "    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", "stderr": "", "exit_code": 0}
13edit_file
{
 "filepath": "fastapi/openapi/utils.py",
 "new_string": "        fastapi.utils.FastAPIDeprecationWarning,",
 "old_string": "        DeprecationWarning,"
}
{"status": "ok", "filepath": "fastapi/openapi/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/openapi/utils.py\n+++ b/fastapi/openapi/u
full
{"status": "ok", "filepath": "fastapi/openapi/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/openapi/utils.py\n+++ b/fastapi/openapi/utils.py\n@@ -217,7 +217,7 @@\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+        fastapi.utils.FastAPIDeprecationWarning,\n         stacklevel=2,\n     )\n     if route.operation_id:\n", "is_truncated": false}
14edit_file
{
 "filepath": "fastapi/utils.py",
 "new_string": "        fastapi.utils.FastAPIDeprecationWarning,",
 "old_string": "        DeprecationWarning,"
}
{"status": "ok", "filepath": "fastapi/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/utils.py\n+++ b/fastapi/utils.py\n@@ -201,7 +201,
full
{"status": "ok", "filepath": "fastapi/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/utils.py\n+++ b/fastapi/utils.py\n@@ -201,7 +201,7 @@\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+        fastapi.utils.FastAPIDeprecationWarning,\n         stacklevel=2,\n     )\n     operation_id = f\"{name}{path}\"\n", "is_truncated": false}
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": "sed -n '70,85p' fastapi/params.py"
}
{"status": "ok", "stdout": " deprecated: Union[deprecated, str, bool, None] = None,\n include_in_schema: bool = True,\n json_schema_extra: Union[dict[str, Any],
full
{"status": "ok", "stdout": "        deprecated: Union[deprecated, str, bool, None] = None,\n        include_in_schema: bool = True,\n        json_schema_extra: Union[dict[str, Any], None] = None,\n        **extra: Any,\n    ):\n        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n        self.openapi_examples = openapi_examples\n        kwargs = dict(\n            default=default,\n", "stderr": "", "exit_code": 0}
17edit_file
{
 "filepath": "fastapi/params.py",
 "new_string": "                category=fastapi.utils.FastAPIDeprecationWarning,",
 "old_string": "                category=DeprecationWarning,",
 "allow_multiple": true
}
{"status": "ok", "filepath": "fastapi/params.py", "occurrences": 4, "strategy": "exact", "diff": "--- a/fastapi/params.py\n+++ b/fastapi/params.py\n@@ -75,7 +75
full
{"status": "ok", "filepath": "fastapi/params.py", "occurrences": 4, "strategy": "exact", "diff": "--- a/fastapi/params.py\n+++ b/fastapi/params.py\n@@ -75,7 +75,7 @@\n         if example is not _Unset:\n             warnings.warn(\n                 \"`example` has been deprecated, please use `examples` instead\",\n-                category=DeprecationWarning,\n+                category=fastapi.utils.FastAPIDeprecationWarning,\n                 stacklevel=4,\n             )\n         self.example = example\n@@ -105,7 +105,7 @@\n         if regex is not None:\n             warnings.warn(\n                 \"`regex` has been deprecated, please use `pattern` instead\",\n-                category=DeprecationWarning,\n+                category=fastapi.utils.FastAPIDeprecationWarning,\n                 stacklevel=4,\n             )\n         current_json_schema_extra = json_schema_extra or extra\n@@ -530,7 +530,7 @@\n         if example is not _Unset:\n             warnings.warn(\n                 \"`example` has been deprecated, please use `examples` instead\",\n-                category=DeprecationWarning,\n+                category=fastapi.utils.FastAPIDeprecationWarning,\n                 stacklevel=4,\n             )\n         self.example = example\n@@ -560,7 +560,7 @@\n         if regex is not None:\n             warnings.warn(\n                 \"`regex` has been deprecated, please use `pattern` instead\",\n-                category=DeprecationWarning,\n+                category=fastapi.utils.FastAPIDeprecationWarning,\n                 stacklevel=4,\n             )\n         current_json_schema_extra = json_schema_extra or extra\n", "is_truncated": false}
18run_command
{
 "command": "sed -n '320,340p' fastapi/dependencies/utils.py"
}
{"status": "ok", "stdout": " ):\n assert param_details.field is None, (\n f\"Cannot specify multiple FastAPI annotations for {param_name!r}\"\n )\n continue\n a
full
{"status": "ok", "stdout": "        ):\n            assert param_details.field is None, (\n                f\"Cannot specify multiple FastAPI annotations for {param_name!r}\"\n            )\n            continue\n        assert param_details.field is not None\n        if isinstance(param_details.field, may_v1.ModelField):\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                stacklevel=5,\n            )\n        if isinstance(\n            param_details.field.field_info, (params.Body, temp_pydantic_v1_params.Body)\n        ):\n            dependant.body_params.append(param_details.field)\n        else:\n            add_param_to_fields(field=param_details.field, dependant=dependant)\n    return dependant\n\n", "stderr": "", "exit_code": 0}
19edit_file
{
 "filepath": "fastapi/dependencies/utils.py",
 "new_string": "                category=fastapi.utils.FastAPIDeprecationWarning,",
 "old_string": "                category=DeprecationWarning,"
}
{"status": "ok", "filepath": "fastapi/dependencies/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/dependencies/utils.py\n+++ b/fastapi
full
{"status": "ok", "filepath": "fastapi/dependencies/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/dependencies/utils.py\n+++ b/fastapi/dependencies/utils.py\n@@ -327,7 +327,7 @@\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=fastapi.utils.FastAPIDeprecationWarning,\n                 stacklevel=5,\n             )\n         if isinstance(\n", "is_truncated": false}
20run_command
{
 "command": "sed -n '640,650p' fastapi/routing.py"
}
{"status": "ok", "stdout": " warnings.warn(\n \"pydantic.v1 is deprecated and will soon stop being supported by FastAPI.\"\n f\" Please update the response mode
full
{"status": "ok", "stdout": "                warnings.warn(\n                    \"pydantic.v1 is deprecated and will soon stop being supported by FastAPI.\"\n                    f\" Please update the response model {self.response_model!r}.\",\n                    category=DeprecationWarning,\n                    stacklevel=4,\n                )\n            self.response_field = create_model_field(\n                name=response_name,\n                type_=self.response_model,\n                mode=\"serialization\",\n            )\n", "stderr": "", "exit_code": 0}
21run_command
{
 "command": "sed -n '680,690p' fastapi/routing.py"
}
{"status": "ok", "stdout": " warnings.warn(\n \"pydantic.v1 is deprecated and will soon stop being supported by FastAPI.\"\n f\" In responses={{}}, please updat
full
{"status": "ok", "stdout": "                    warnings.warn(\n                        \"pydantic.v1 is deprecated and will soon stop being supported by FastAPI.\"\n                        f\" In responses={{}}, please update {model}.\",\n                        category=DeprecationWarning,\n                        stacklevel=4,\n                    )\n                response_field = create_model_field(\n                    name=response_name, type_=model, mode=\"serialization\"\n                )\n                response_fields[additional_status_code] = response_field\n        if response_fields:\n", "stderr": "", "exit_code": 0}
22edit_file
{
 "allow_multiple": true,
 "filepath": "fastapi/routing.py",
 "new_string": "                    category=fastapi.utils.FastAPIDeprecationWarning,",
 "old_string": "                    category=DeprecationWarning,"
}
{"status": "ok", "filepath": "fastapi/routing.py", "occurrences": 2, "strategy": "exact", "diff": "--- a/fastapi/routing.py\n+++ b/fastapi/routing.py\n@@ -640,7
full
{"status": "ok", "filepath": "fastapi/routing.py", "occurrences": 2, "strategy": "exact", "diff": "--- a/fastapi/routing.py\n+++ b/fastapi/routing.py\n@@ -640,7 +640,7 @@\n                 warnings.warn(\n                     \"pydantic.v1 is deprecated and will soon stop being supported by FastAPI.\"\n                     f\" Please update the response model {self.response_model!r}.\",\n-                    category=DeprecationWarning,\n+                    category=fastapi.utils.FastAPIDeprecationWarning,\n                     stacklevel=4,\n                 )\n             self.response_field = create_model_field(\n@@ -680,7 +680,7 @@\n                     warnings.warn(\n                         \"pydantic.v1 is deprecated and will soon stop being supported by FastAPI.\"\n                         f\" In responses={{}}, please update {model}.\",\n-                        category=DeprecationWarning,\n+                        category=fastapi.utils.FastAPIDeprecationWarning,\n                         stacklevel=4,\n                     )\n                 response_field = create_model_field(\n", "is_truncated": false}
23run_command
{
 "command": "sed -n '60,70p' fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "stdout": " json_schema_extra: Union[dict[str, Any], None] = None,\n **extra: Any,\n ):\n if example is not _Unset:\n warnings.warn(\n \"`examp
full
{"status": "ok", "stdout": "        json_schema_extra: Union[dict[str, Any], None] = None,\n        **extra: Any,\n    ):\n        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n", "stderr": "", "exit_code": 0}
24run_command
{
 "command": "sed -n '90,100p' fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "stdout": " )\n if examples is not None:\n kwargs[\"examples\"] = examples\n if regex is not None:\n warnings.warn(\n \"`regex` has been deprec
full
{"status": "ok", "stdout": "        )\n        if examples is not None:\n            kwargs[\"examples\"] = examples\n        if regex is not None:\n            warnings.warn(\n                \"`regex` has been deprecated, please use `pattern` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        current_json_schema_extra = json_schema_extra or extra\n        kwargs[\"deprecated\"] = deprecated\n", "stderr": "", "exit_code": 0}
25run_command
{
 "command": "sed -n '500,510p' fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "stdout": " ):\n self.embed = embed\n self.media_type = media_type\n if example is not _Unset:\n warnings.warn(\n \"`example` has been deprecat
full
{"status": "ok", "stdout": "    ):\n        self.embed = embed\n        self.media_type = media_type\n        if example is not _Unset:\n            warnings.warn(\n                \"`example` has been deprecated, please use `examples` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        self.example = example\n        self.include_in_schema = include_in_schema\n", "stderr": "", "exit_code": 0}
26run_command
{
 "command": "sed -n '530,540p' fastapi/temp_pydantic_v1_params.py"
}
{"status": "ok", "stdout": " )\n if examples is not None:\n kwargs[\"examples\"] = examples\n if regex is not None:\n warnings.warn(\n \"`regex` has been deprec
full
{"status": "ok", "stdout": "        )\n        if examples is not None:\n            kwargs[\"examples\"] = examples\n        if regex is not None:\n            warnings.warn(\n                \"`regex` has been deprecated, please use `pattern` instead\",\n                category=DeprecationWarning,\n                stacklevel=4,\n            )\n        current_json_schema_extra = json_schema_extra or extra\n        kwargs[\"deprecated\"] = deprecated\n", "stderr": "", "exit_code": 0}
27edit_file
{
 "allow_multiple": true,
 "filepath": "fastapi/temp_pydantic_v1_params.py",
 "new_string": "                category=fastapi.utils.FastAPIDeprecationWarning,",
 "old_string": "                category=DeprecationWarning,"
}
{"status": "ok", "filepath": "fastapi/temp_pydantic_v1_params.py", "occurrences": 4, "strategy": "exact", "diff": "--- a/fastapi/temp_pydantic_v1_params.py\n+++
full
{"status": "ok", "filepath": "fastapi/temp_pydantic_v1_params.py", "occurrences": 4, "strategy": "exact", "diff": "--- a/fastapi/temp_pydantic_v1_params.py\n+++ b/fastapi/temp_pydantic_v1_params.py\n@@ -63,7 +63,7 @@\n         if example is not _Unset:\n             warnings.warn(\n                 \"`example` has been deprecated, please use `examples` instead\",\n-                category=DeprecationWarning,\n+                category=fastapi.utils.FastAPIDeprecationWarning,\n                 stacklevel=4,\n             )\n         self.example = example\n@@ -93,7 +93,7 @@\n         if regex is not None:\n             warnings.warn(\n                 \"`regex` has been deprecated, please use `pattern` instead\",\n-                category=DeprecationWarning,\n+                category=fastapi.utils.FastAPIDeprecationWarning,\n                 stacklevel=4,\n             )\n         current_json_schema_extra = json_schema_extra or extra\n@@ -503,7 +503,7 @@\n         if example is not _Unset:\n             warnings.warn(\n                 \"`example` has been deprecated, please use `examples` instead\",\n-                category=DeprecationWarning,\n+                category=fastapi.utils.FastAPIDeprecationWarning,\n                 stacklevel=4,\n             )\n         self.example = example\n@@ -533,7 +533,7 @@\n         if regex is not None:\n             warnings.warn(\n                 \"`regex` has been deprecated, please use `pattern` instead\",\n-                category=DeprecationWarning,\n+                category=fastapi.utils.FastAPIDeprecationWarning,\n                 stacklevel=4,\n             )\n         current_json_schema_extra = json_schema_extra or extra\n", "is_truncated": false}
28run_command
{
 "command": "grep -rn \"DeprecationWarning\" fastapi | grep -v \"FastAPIDeprecationWarning\" | head -20"
}
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
full
{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}
29submit_patch
{}
{"status": "ok", "patch_size": 6576, "files_changed": 6}
full
{"status": "ok", "patch_size": 6576, "files_changed": 6}

Patch

diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py
index 39d0bd89..fd97c0cb 100644
--- a/fastapi/dependencies/utils.py
+++ b/fastapi/dependencies/utils.py
@@ -327,7 +327,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=fastapi.utils.FastAPIDeprecationWarning,
                 stacklevel=5,
             )
         if isinstance(
diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py
index a99d4188..0e057efe 100644
--- a/fastapi/openapi/utils.py
+++ b/fastapi/openapi/utils.py
@@ -217,7 +217,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,
+        fastapi.utils.FastAPIDeprecationWarning,
         stacklevel=2,
     )
     if route.operation_id:
diff --git a/fastapi/params.py b/fastapi/params.py
index c776c4a5..fed67b15 100644
--- a/fastapi/params.py
+++ b/fastapi/params.py
@@ -75,7 +75,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=fastapi.utils.FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         self.example = example
@@ -105,7 +105,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=fastapi.utils.FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         current_json_schema_extra = json_schema_extra or extra
@@ -530,7 +530,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=fastapi.utils.FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         self.example = example
@@ -560,7 +560,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=fastapi.utils.FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         current_json_schema_extra = json_schema_extra or extra
diff --git a/fastapi/routing.py b/fastapi/routing.py
index 2770e325..0395a1e1 100644
--- a/fastapi/routing.py
+++ b/fastapi/routing.py
@@ -640,7 +640,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=fastapi.utils.FastAPIDeprecationWarning,
                     stacklevel=4,
                 )
             self.response_field = create_model_field(
@@ -680,7 +680,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=fastapi.utils.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..6930fd3c 100644
--- a/fastapi/temp_pydantic_v1_params.py
+++ b/fastapi/temp_pydantic_v1_params.py
@@ -63,7 +63,7 @@ class Param(FieldInfo):
         if example is not _Unset:
             warnings.warn(
                 "`example` has been deprecated, please use `examples` instead",
-                category=DeprecationWarning,
+                category=fastapi.utils.FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         self.example = example
@@ -93,7 +93,7 @@ class Param(FieldInfo):
         if regex is not None:
             warnings.warn(
                 "`regex` has been deprecated, please use `pattern` instead",
-                category=DeprecationWarning,
+                category=fastapi.utils.FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         current_json_schema_extra = json_schema_extra or extra
@@ -503,7 +503,7 @@ class Body(FieldInfo):
         if example is not _Unset:
             warnings.warn(
                 "`example` has been deprecated, please use `examples` instead",
-                category=DeprecationWarning,
+                category=fastapi.utils.FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         self.example = example
@@ -533,7 +533,7 @@ class Body(FieldInfo):
         if regex is not None:
             warnings.warn(
                 "`regex` has been deprecated, please use `pattern` instead",
-                category=DeprecationWarning,
+                category=fastapi.utils.FastAPIDeprecationWarning,
                 stacklevel=4,
             )
         current_json_schema_extra = json_schema_extra or extra
diff --git a/fastapi/utils.py b/fastapi/utils.py
index c4631d7e..d86aa8ad 100644
--- a/fastapi/utils.py
+++ b/fastapi/utils.py
@@ -38,6 +38,10 @@ _CLONED_TYPES_CACHE: MutableMapping[type[BaseModel], type[BaseModel]] = (
 )
 
 
+class FastAPIDeprecationWarning(DeprecationWarning):
+    pass
+
+
 def is_body_allowed_for_status_code(status_code: Union[int, str, None]) -> bool:
     if status_code is None:
         return True
@@ -197,7 +201,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,
+        fastapi.utils.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_r1_v1n/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_r1_v1n/fastapi_14605/b/workspace/fastapi/exceptions.py)
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 error in 0.41s