beanie: Beanie 1.21 still triggers many deprecation warnings with Pydantic v2
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/
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Reactions: 2
- Comments: 16 (4 by maintainers)
Still relevant.
From: github-actions[bot] @.> Sent: Thursday, December 14, 2023 10:50:02 PM To: roman-right/beanie @.> Cc: WarpedPixel @.>; Author @.> Subject: Re: [roman-right/beanie] Beanie 1.21 still triggers many deprecation warnings with Pydantic v2 (Issue #676)
This issue is stale because it has been open 30 days with no activity.
— Reply to this email directly, view it on GitHubhttps://github.com/roman-right/beanie/issues/676#issuecomment-1857143721, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABUVFOB5V3ZMKJF7ZBV4MW3YJOUEVAVCNFSM6AAAAAA36YKI46VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJXGE2DGNZSGE. You are receiving this because you authored the thread.Message ID: @.***>
Looks like there are some more recent deprecation’s are surfacing from https://github.com/pydantic/pydantic-core/pull/980. E.g.,:
Also many new deprecation warnings with latest Pydantic v2.5.0 like this one:
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.