BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
1.99k stars 211 forks source link

patch: update deprecated core_schema function #722

Closed sorXCode closed 9 months ago

sorXCode commented 11 months ago

Purpose

This PR fixes some deprecation warnings while using Pydantic v2.

Context

There were deprecation warnings while running pytest in my PydanticV2 (2.4.1) project.

====================================== warnings summary ======================================
venv/lib/python3.10/site-packages/beanie/odm/fields.py:544
  venv/lib/python3.10/site-packages/beanie/odm/fields.py:544: DeprecationWarning: `general_plain_validator_function` is deprecated, use `with_info_plain_validator_function` instead.
    return core_schema.general_plain_validator_function(validate)

venv/lib/python3.10/site-packages/pydantic_core/core_schema.py:3898
venv/lib/python3.10/site-packages/pydantic_core/core_schema.py:3898
venv/lib/python3.10/site-packages/pydantic_core/core_schema.py:3898
venv/lib/python3.10/site-packages/pydantic_core/core_schema.py:3898
venv/lib/python3.10/site-packages/pydantic_core/core_schema.py:3898
venv/lib/python3.10/site-packages/pydantic_core/core_schema.py:3898
  venv/lib/python3.10/site-packages/pydantic_core/core_schema.py:3898: DeprecationWarning: `general_plain_validator_function` is deprecated, use `with_info_plain_validator_function` instead.
    warnings.warn(

venv/lib/python3.10/site-packages/beanie/odm/fields.py:123
venv/lib/python3.10/site-packages/beanie/odm/fields.py:123
venv/lib/python3.10/site-packages/beanie/odm/fields.py:123
venv/lib/python3.10/site-packages/beanie/odm/fields.py:123
venv/lib/python3.10/site-packages/beanie/odm/fields.py:123
  venv/lib/python3.10/site-packages/beanie/odm/fields.py:123: DeprecationWarning: `general_plain_validator_function` is deprecated, use `with_info_plain_validator_function` instead.
    python_schema=core_schema.general_plain_validator_function(
roman-right commented 11 months ago

Thank you for the PR, I'll check it this week

sorXCode commented 11 months ago

@roman-right, I've fixed the pre-commit hook failure. I also discovered that the general_plain_validator_function was deprecated and the new with_info_plain_validator_function introduced in Pydantic_core 2.10 (PR here, release here), whereas the GitHub Action in this repo uses Pydantic v2.3 (Pydantic_core 2.6.3), hence the failure.

What do you think could be done in this scenario? Perhaps adding an "if block" for Pydantic >2.3 is safe?

roman-right commented 11 months ago

Thank you for the PR! I'll check it again and merge by the end of this week

roman-right commented 11 months ago

It looks like it doesn't work with Pydantic V2 (Or should I update my gh-actions?)

roman-right commented 9 months ago

It looks like this PR is not in work more. If no, feel free to open a new one.