Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beanie 1.21 still triggers many deprecation warnings with Pydantic v2 #676

Closed
WarpedPixel opened this issue Aug 25, 2023 · 16 comments
Closed
Labels

Comments

@WarpedPixel
Copy link

Describe the bug
There are many Pydantic v2 deprecation warnings triggered by beanie code.

To Reproduce
run python code using beanie 1.21 with -W error to stop at the first warning.

Example:

../../../Library/Caches/pypoetry/virtualenvs/companion-mgXvcyvA-py3.11/lib/python3.11/site-packages/pydantic/_internal/_config.py:219: in prepare_config
    warnings.warn(DEPRECATION_MESSAGE, DeprecationWarning)
E   pydantic.warnings.PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.3/migration/

Triggered by this code in beanie/odm/bulk.py:

class Operation(BaseModel):
    operation: Union[
        Type[InsertOne],
        Type[DeleteOne],
        Type[DeleteMany],
        Type[ReplaceOne],
        Type[UpdateOne],
        Type[UpdateMany],
    ]
    first_query: Mapping[str, Any]
    second_query: Optional[Dict[str, Any]] = None
    pymongo_kwargs: Dict[str, Any] = Field(default_factory=dict)
    object_class: Type

    class Config:
        arbitrary_types_allowed = True

Expected behavior
Clean run with no deprecations.

Additional context
I see primarily these 4 types of deprecation warnings:

  /Users/bcs/Library/Caches/pypoetry/virtualenvs/companion-mgXvcyvA-py3.11/lib/python3.11/site-packages/beanie/odm/utils/init.py:386: PydanticDeprecatedSince20: The `__fields__` attribute is deprecated, use `model_fields` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.3/migration/
  /Users/bcs/Library/Caches/pypoetry/virtualenvs/companion-mgXvcyvA-py3.11/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: 'hidden'). Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.3/migration/
  /Users/bcs/Library/Caches/pypoetry/virtualenvs/companion-mgXvcyvA-py3.11/lib/python3.11/site-packages/beanie/odm/documents.py:210: PydanticDeprecatedSince20: Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more details. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.3/migration/
  /Users/bcs/Library/Caches/pypoetry/virtualenvs/companion-mgXvcyvA-py3.11/lib/python3.11/site-packages/beanie/odm/utils/encoder.py:113: PydanticDeprecatedSince20: The private method `_iter` will be removed and should no longer be used. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.3/migration/


@roman-right
Copy link
Member

Thank you for the catch. Fixed in #669

@jhamman
Copy link

jhamman commented Sep 12, 2023

I'm testing #669 and am still seeing one warning:

  .../site-packages/beanie/odm/utils/init.py:386: PydanticDeprecatedSince20: The `__fields__` attribute is deprecated, use `model_fields` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.3/migration/
    f = getattr(cls, attr)

@roman-right
Copy link
Member

I see this one too. It happens because Pydantic still has this field in the models. During initialization, I need to check all the fields that exist at the class level to do some pre-processing with some of them. So, I'm checking this one too. It is not used anywhere. I thought about adding an ignore list, but it seems redundant and potentially difficult to maintain the correct list of attributes to ignore.
When Pydantic no longer has this class property, this warning will be gone.

@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity.

@github-actions github-actions bot added the Stale label Oct 14, 2023
@peterschutt
Copy link

Looks like there are some more recent deprecation's are surfacing from pydantic/pydantic-core#980. E.g.,:

/beanie/odm/fields.py:554: DeprecationWarning: `general_plain_validator_function` is deprecated, use `with_info_plain_validator_function` instead.
    return core_schema.general_plain_validator_function(validate)

@github-actions github-actions bot removed the Stale label Oct 17, 2023
@WarpedPixel
Copy link
Author

Also many new deprecation warnings with latest Pydantic v2.5.0 like this one:

  /Users/xxx/Library/Caches/pypoetry/virtualenvs/mgXvcyvA-py3.11/lib/python3.11/site-packages/beanie/odm/fields.py:150: DeprecationWarning: `general_plain_validator_function` is deprecated, use `with_info_plain_validator_function` instead.
    python_schema=core_schema.general_plain_validator_function(

@bkis
Copy link

bkis commented Nov 14, 2023

I got some of these, too:

Beanie version: 1.23.6
Pydantic version: 2.5.0

DeprecationWarning: `general_plain_validator_function` is deprecated, use `with_info_plain_validator_function` instead.

...at beanie/odm/fields.py:581 and beanie/odm/fields.py:150, and...

PydanticDeprecatedSince20: The `__fields__` attribute is deprecated, use `model_fields` instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.5/migration/

...at beanie/odm/utils/init.py:394.

Copy link
Contributor

This issue is stale because it has been open 30 days with no activity.

@github-actions github-actions bot added the Stale label Dec 15, 2023
@WarpedPixel
Copy link
Author

WarpedPixel commented Dec 16, 2023 via email

@github-actions github-actions bot removed the Stale label Dec 17, 2023
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity.

@github-actions github-actions bot added the Stale label Jan 17, 2024
@jhamman
Copy link

jhamman commented Jan 17, 2024

Question for @roman-right - how long do you expect to support Pydantic v1 alongside v2?

@roman-right
Copy link
Member

Hi @jhamman,
I plan to support v1 at least for this year.
I think a good metric would be the weekly downloads by version. For now, 1.10 is the most popular version based on this metric. When 2.x becomes twice as popular as 1.x, it will probably be safe to stop supporting v1.
https://snyk.io/advisor/python/pydantic

@roman-right
Copy link
Member

Regarding the warnings, every new minor version of Pydantic introduces new deprecations. I will fix them if possible, but they will always be present.

@github-actions github-actions bot removed the Stale label Jan 18, 2024
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity.

@github-actions github-actions bot added the Stale label Feb 18, 2024
Copy link
Contributor

github-actions bot commented Mar 4, 2024

This issue was closed because it has been stalled for 14 days with no activity.

@github-actions github-actions bot closed this as completed Mar 4, 2024
@dslemusp
Copy link
Contributor

Regarding the warnings, every new minor version of Pydantic introduces new deprecations. I will fix them if possible, but they will always be present.

Small contribution #897

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants