-
Notifications
You must be signed in to change notification settings - Fork 15
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
[WIP] Upgrade to Pydantic v2 #413
Conversation
@@ -30,7 +30,8 @@ install_requires = | |||
; By default, we only consider core dependencies required to use Ralph as a | |||
; library (mostly models). | |||
langcodes>=3.2.0 | |||
pydantic[dotenv,email]>=1.10.0, <2.0 | |||
pydantic[email]>=2.1.1, <3.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pydantic[email]>=2.1.1, <3.0 | |
pydantic[email]>=2.1.1 |
@@ -124,11 +131,11 @@ class MongoClientOptions(ClientOptions): | |||
|
|||
|
|||
class ESDatabaseBackendSettings(InstantiableSettingsItem): | |||
"""Pydantic modelf for Elasticsearch database backend configuration settings.""" | |||
"""Pydantic modelf for Elasticsearch database backend configuration settings.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Pydantic modelf for Elasticsearch database backend configuration settings.""" | |
"""Pydantic model for Elasticsearch database backend configuration settings.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -3,12 +3,12 @@ | |||
import io | |||
from enum import Enum | |||
from pathlib import Path | |||
from typing import List, Tuple, Union | |||
from typing import Any, List, Tuple, Union |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from typing import Any, List, Tuple, Union | |
from typing import Any, List, Optional, Tuple, Union |
|
||
try: | ||
from typing import Literal | ||
from typing import Annotated, Literal, Optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from typing import Annotated, Literal, Optional | |
from typing import Annotated, Literal |
except ImportError: | ||
from typing_extensions import Literal | ||
from typing_extensions import Annotated, Literal, Optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from typing_extensions import Annotated, Literal, Optional | |
from typing_extensions import Annotated, Literal |
@@ -30,7 +30,8 @@ install_requires = | |||
; By default, we only consider core dependencies required to use Ralph as a | |||
; library (mostly models). | |||
langcodes>=3.2.0 | |||
pydantic[dotenv,email]>=1.10.0, <2.0 | |||
pydantic[email]>=2.1.1, <3.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pydantic[email]>=2.1.1, <3.0 | |
pydantic[email]>=2.2.0 |
replaced by #504 |
Purpose
As mentionned in #401 , upgrading to pydantic 2 should greatly improve performances. Also it would allow projects depending on
ralph
(such aswarren
) to upgrade more easily.Dealing with common errors when migrating
ERROR: Extra not permitted
In
conf.py
, errors such as:may be due to a change in default behavior in models
extra=ignore
toextra=failure
. We may set this parameter manually to fix this issue.ERROR: Unable to generate pydantic-core schema
To fix this we change the way we define classes.
Previously in Ralph
New in Ralph
ERROR: Missing values
A recurrent error is the one below, which should be linked to the change of behavior when using
Optional[...]
in Pydantic V2. Previously, it would assign a default value ofNone
, which is no longer the case. This should have been dealt with bybump-pydantic
but was not always the case. It would be nice to know why before confirming this solution.Previously in Ralph
New in Ralph