pgjones / quart-schema

Quart-Schema is a Quart extension that provides schema validation and auto-generated API documentation.
MIT License
76 stars 24 forks source link

Pydantic V2 deprecation warnings #66

Closed mst-ableton closed 10 months ago

mst-ableton commented 10 months ago

Hello, thanks for quart-schema!

When encoding a type that pydantic knows about but the default JSON encoder doesn't, some deprecation warnings appear:

PydanticDeprecatedSince20: pydantic_encoder is deprecated, use pydantic_core.to_jsonable_python instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.4/migration/

and

PydanticDeprecatedSince20: pydantic_encoder is deprecated, use BaseModel.model_dump instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.4/migration

The affected code for the first warning seems to be here: https://github.com/pgjones/quart-schema/blob/a2171e82cf20ae070c5471e4ae353a2cb3e55846/src/quart_schema/extension.py#L116

I'm not sure about the second one, the line shows python3.10/site-packages/typing_extensions.py:2360 but that doesn't make a lot of sense.

Code that triggers this:

from http import HTTPStatus
from uuid import UUID

import pytest
import pytest_asyncio

from pydantic import BaseModel
from quart import Quart
from quart_schema import QuartSchema, validate_response

app = Quart(__name__)

QuartSchema(app)

class UUIDResponse(BaseModel):
    uuid: UUID

@app.route("/")
@validate_response(UUIDResponse, HTTPStatus.OK)
async def root() -> tuple[UUIDResponse, int]:
    """Root page."""
    return UUIDResponse(uuid="00000000-0000-0000-0000-000000000000"), HTTPStatus.OK

@pytest.mark.asyncio
async def test_root():
    """Test that the root page loads."""
    r = await app.test_client().get("/")

    assert r.status_code == HTTPStatus.OK

For reference, this was with Python 3.10.12, and pip list says:

Package           Version
----------------- -------
aiofiles          23.2.1
annotated-types   0.6.0
blinker           1.6.3
click             8.1.7
exceptiongroup    1.1.3
Flask             3.0.0
h11               0.14.0
h2                4.1.0
hpack             4.0.0
hypercorn         0.14.4
hyperframe        6.0.1
iniconfig         2.0.0
itsdangerous      2.1.2
Jinja2            3.1.2
MarkupSafe        2.1.3
packaging         23.2
pip               23.0.1
pluggy            1.3.0
priority          2.0.0
pydantic          2.4.2
pydantic_core     2.10.1
pyhumps           3.8.0
pytest            7.4.2
pytest-asyncio    0.21.1
Quart             0.19.3
quart-schema      0.17.1
setuptools        65.5.0
tomli             2.0.1
typing_extensions 4.8.0
Werkzeug          3.0.0
wsproto           1.2.0
pgjones commented 10 months ago

Should be fixed with c17bfbf5d5db86fddac988e2735742ceace91159, please reopen if not.