contextmanager_in_threadpool,
)
from fastapi.dependencies.models import Dependant
-from fastapi.exceptions import DependencyScopeError
+from fastapi.exceptions import DependencyScopeError, FastAPIDeprecationWarning
from fastapi.logger import logger
from fastapi.security.oauth2 import SecurityScopes
from fastapi.types import DependencyCacheKey
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(
) -> None:
super().__init__(errors, endpoint_ctx=endpoint_ctx)
self.body = body
+
+
+class FastAPIDeprecationWarning(UserWarning):
+ """
+ A custom deprecation warning as DeprecationWarning is ignored
+ Ref: https://sethmlarson.dev/deprecations-via-warnings-dont-work-for-python-libraries
+ """
get_validation_alias,
)
from fastapi.encoders import jsonable_encoder
+from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.openapi.constants import METHODS_WITH_BODY, REF_PREFIX
from fastapi.openapi.models import OpenAPI
from fastapi.params import Body, ParamTypes
*, route: routing.APIRoute, method: str
) -> str: # pragma: nocover
warnings.warn(
- "fastapi.openapi.utils.generate_operation_id() was deprecated, "
+ message="fastapi.openapi.utils.generate_operation_id() was deprecated, "
"it is not used internally, and will be removed soon",
- DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=2,
)
if route.operation_id:
from enum import Enum
from typing import Annotated, Any, Callable, Optional, Union
+from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.openapi.models import Example
from pydantic.fields import FieldInfo
from typing_extensions import Literal, deprecated
if example is not _Unset:
warnings.warn(
"`example` has been deprecated, please use `examples` instead",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
self.example = example
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
if example is not _Unset:
warnings.warn(
"`example` has been deprecated, please use `examples` instead",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
self.example = example
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
from fastapi.encoders import jsonable_encoder
from fastapi.exceptions import (
EndpointContext,
+ FastAPIDeprecationWarning,
FastAPIError,
RequestValidationError,
ResponseValidationError,
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(
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(
import warnings
from typing import Annotated, Any, Callable, Optional, Union
+from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.openapi.models import Example
from fastapi.params import ParamTypes
from typing_extensions import deprecated
if example is not _Unset:
warnings.warn(
"`example` has been deprecated, please use `examples` instead",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
self.example = example
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
if example is not _Unset:
warnings.warn(
"`example` has been deprecated, please use `examples` instead",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=4,
)
self.example = example
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
may_v1,
)
from fastapi.datastructures import DefaultPlaceholder, DefaultType
+from fastapi.exceptions import FastAPIDeprecationWarning
from pydantic import BaseModel
from pydantic.fields import FieldInfo
from typing_extensions import Literal
*, name: str, path: str, method: str
) -> str: # pragma: nocover
warnings.warn(
- "fastapi.utils.generate_operation_id_for_path() was deprecated, "
+ message="fastapi.utils.generate_operation_id_for_path() was deprecated, "
"it is not used internally, and will be removed soon",
- DeprecationWarning,
+ category=FastAPIDeprecationWarning,
stacklevel=2,
)
operation_id = f"{name}{path}"
import pytest
from fastapi import Depends, FastAPI
+from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.testclient import TestClient
if "--codspeed" not in sys.argv:
warnings.filterwarnings(
"ignore",
message=r"pydantic\.v1 is deprecated and will soon stop being supported by FastAPI\..*",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
)
@app.post("/sync/validated", response_model=ItemOut)
from typing import Optional
import pytest
+from fastapi.exceptions import FastAPIDeprecationWarning
from tests.utils import skip_module_if_py_gte_314
# Deprecation warning tests for regex parameter
def test_query_regex_deprecation_warning():
- with pytest.warns(DeprecationWarning, match="`regex` has been deprecated"):
+ with pytest.warns(FastAPIDeprecationWarning, match="`regex` has been deprecated"):
Query(regex="^test$")
def test_body_regex_deprecation_warning():
- with pytest.warns(DeprecationWarning, match="`regex` has been deprecated"):
+ with pytest.warns(FastAPIDeprecationWarning, match="`regex` has been deprecated"):
Body(regex="^test$")
# Deprecation warning tests for example parameter
def test_query_example_deprecation_warning():
- with pytest.warns(DeprecationWarning, match="`example` has been deprecated"):
+ with pytest.warns(FastAPIDeprecationWarning, match="`example` has been deprecated"):
Query(example="test example")
def test_body_example_deprecation_warning():
- with pytest.warns(DeprecationWarning, match="`example` has been deprecated"):
+ with pytest.warns(FastAPIDeprecationWarning, match="`example` has been deprecated"):
Body(example={"test": "example"})
import sys
import pytest
+from fastapi.exceptions import FastAPIDeprecationWarning
from tests.utils import skip_module_if_py_gte_314
app = FastAPI()
with pytest.warns(
- DeprecationWarning,
+ FastAPIDeprecationWarning,
match=r"pydantic\.v1 is deprecated.*Please update the param data:",
):
app = FastAPI()
with pytest.warns(
- DeprecationWarning,
+ FastAPIDeprecationWarning,
match=r"pydantic\.v1 is deprecated.*Please update the response model",
):
app = FastAPI()
with pytest.warns(
- DeprecationWarning,
+ FastAPIDeprecationWarning,
match=r"pydantic\.v1 is deprecated.*Please update the response model",
):
app = FastAPI()
with pytest.warns(
- DeprecationWarning,
+ FastAPIDeprecationWarning,
match=r"pydantic\.v1 is deprecated.*In responses=\{\}, please update",
):
import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, Form
+from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.testclient import TestClient
from .utils import needs_py310
def get_client():
app = FastAPI()
- with pytest.warns(DeprecationWarning):
+ with pytest.warns(FastAPIDeprecationWarning):
@app.post("/items/")
async def read_items(
import pytest
from dirty_equals import IsDict
from fastapi import FastAPI, Query
+from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.testclient import TestClient
from .utils import needs_py310
def get_client():
app = FastAPI()
- with pytest.warns(DeprecationWarning):
+ with pytest.warns(FastAPIDeprecationWarning):
@app.get("/items/")
async def read_items(
import pytest
from dirty_equals import IsDict
from fastapi import Body, Cookie, FastAPI, Header, Path, Query
+from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.testclient import TestClient
from pydantic import BaseModel, ConfigDict
def schema_extra(item: Item):
return item
- with pytest.warns(DeprecationWarning):
+ with pytest.warns(FastAPIDeprecationWarning):
@app.post("/example/")
def example(item: Item = Body(example={"data": "Data in Body example"})):
):
return item
- with pytest.warns(DeprecationWarning):
+ with pytest.warns(FastAPIDeprecationWarning):
@app.post("/example_examples/")
def example_examples(
# ):
# return lastname
- with pytest.warns(DeprecationWarning):
+ with pytest.warns(FastAPIDeprecationWarning):
@app.get("/path_example/{item_id}")
def path_example(
):
return item_id
- with pytest.warns(DeprecationWarning):
+ with pytest.warns(FastAPIDeprecationWarning):
@app.get("/path_example_examples/{item_id}")
def path_example_examples(
):
return item_id
- with pytest.warns(DeprecationWarning):
+ with pytest.warns(FastAPIDeprecationWarning):
@app.get("/query_example/")
def query_example(
):
return data
- with pytest.warns(DeprecationWarning):
+ with pytest.warns(FastAPIDeprecationWarning):
@app.get("/query_example_examples/")
def query_example_examples(
):
return data
- with pytest.warns(DeprecationWarning):
+ with pytest.warns(FastAPIDeprecationWarning):
@app.get("/header_example/")
def header_example(
):
return data
- with pytest.warns(DeprecationWarning):
+ with pytest.warns(FastAPIDeprecationWarning):
@app.get("/header_example_examples/")
def header_example_examples(
):
return data
- with pytest.warns(DeprecationWarning):
+ with pytest.warns(FastAPIDeprecationWarning):
@app.get("/cookie_example/")
def cookie_example(
):
return data
- with pytest.warns(DeprecationWarning):
+ with pytest.warns(FastAPIDeprecationWarning):
@app.get("/cookie_example_examples/")
def cookie_example_examples(
import warnings
import pytest
+from fastapi.exceptions import FastAPIDeprecationWarning
from inline_snapshot import snapshot
from tests.utils import skip_module_if_py_gte_314
warnings.filterwarnings(
"ignore",
message=r"pydantic\.v1 is deprecated and will soon stop being supported by FastAPI\..*",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
)
mod = importlib.import_module(f"docs_src.pydantic_v1_in_v2.{request.param}")
import warnings
import pytest
+from fastapi.exceptions import FastAPIDeprecationWarning
from inline_snapshot import snapshot
from tests.utils import skip_module_if_py_gte_314
warnings.filterwarnings(
"ignore",
message=r"pydantic\.v1 is deprecated and will soon stop being supported by FastAPI\..*",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
)
mod = importlib.import_module(f"docs_src.pydantic_v1_in_v2.{request.param}")
import warnings
import pytest
+from fastapi.exceptions import FastAPIDeprecationWarning
from inline_snapshot import snapshot
from tests.utils import skip_module_if_py_gte_314
warnings.filterwarnings(
"ignore",
message=r"pydantic\.v1 is deprecated and will soon stop being supported by FastAPI\..*",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
)
mod = importlib.import_module(f"docs_src.pydantic_v1_in_v2.{request.param}")
marks=(
needs_py310,
pytest.mark.filterwarnings(
- "ignore:`regex` has been deprecated, please use `pattern` instead:DeprecationWarning"
+ "ignore:`regex` has been deprecated, please use `pattern` instead:fastapi.exceptions.FastAPIDeprecationWarning"
),
),
),
import warnings
import pytest
+from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.testclient import TestClient
from ...utils import needs_pydanticv1
warnings.filterwarnings(
"ignore",
message=r"pydantic\.v1 is deprecated and will soon stop being supported by FastAPI\..*",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
)
mod = importlib.import_module(f"docs_src.request_form_models.{request.param}")
import warnings
import pytest
+from fastapi.exceptions import FastAPIDeprecationWarning
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
warnings.filterwarnings(
"ignore",
message=r"pydantic\.v1 is deprecated and will soon stop being supported by FastAPI\..*",
- category=DeprecationWarning,
+ category=FastAPIDeprecationWarning,
)
mod = importlib.import_module(f"docs_src.schema_extra_example.{request.param}")