litestar icon indicating copy to clipboard operation
litestar copied to clipboard

Bug: `__dto__` key for `pydantic.Field` is deprecated and will be removed in v3

Open sobolevn opened this issue 2 years ago • 2 comments

Description

Right now dto_field() sets __dto__ attribute on pydantic.Field: https://github.com/litestar-org/litestar/blob/645e41e787b9cb0697bdb32e2997e9149cc49705/tests/unit/test_contrib/test_pydantic/test_pydantic_dto_factory.py#L20-L22

However, this behavior is deprecated:

tests/unit/test_contrib/test_pydantic/test_pydantic_dto_factory.py::test_field_definition_generation
tests/unit/test_contrib/test_pydantic/test_pydantic_dto_factory.py::test_field_definition_generation
  /home/runner/work/litestar/litestar/.venv/lib/python3.11/site-packages/pydantic/fields.py:792: PydanticDeprecatedSince20: Using extra keyword arguments on `Field` is deprecated and will be removed. Use `json_schema_extra` instead. (Extra keys: '__dto__'). Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.3/migration/
    warn(

Looks like we need to rework how dto_field is set on pydantic.Field

URL to code causing the issue

No response

MCVE

No response

Steps to reproduce

No response

Screenshots

No response

Logs

No response

Litestar Version

main

Platform

  • [X] Linux
  • [X] Mac
  • [X] Windows
  • [ ] Other (Please specify in the description above)

Funding

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
Fund with Polar

sobolevn avatar Sep 24 '23 07:09 sobolevn

@peterschutt, any ideas?

provinzkraut avatar Sep 24 '23 08:09 provinzkraut

@peterschutt, any ideas?

Maybe via Annotated?

peterschutt avatar Sep 24 '23 08:09 peterschutt

This issue has been closed in #3289. The change will be included in the upcoming patch release.

github-actions[bot] avatar Mar 30 '24 10:03 github-actions[bot]

A fix for this issue has been released in v2.8.0

github-actions[bot] avatar Apr 05 '24 20:04 github-actions[bot]