-
Notifications
You must be signed in to change notification settings - Fork 27
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
⬆️ Upgrade models-library (pydantic v2) #6333
Merged
giancarloromeo
merged 74 commits into
ITISFoundation:pydantic_v2_migration
from
giancarloromeo:is4481/upgrade-models-library
Sep 18, 2024
Merged
Changes from 4 commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
6c6bebc
remove version constraint
giancarloromeo 533bdd1
upgrade requirements
giancarloromeo c1bbc52
run bump-pydantic
giancarloromeo 76f0fc6
fix bump-pydantic issues
giancarloromeo 55b72c7
fix bump-pydantic issues
giancarloromeo df01a19
fix bump-pydantic issues
giancarloromeo 41b8797
fix bump-pydantic issues
giancarloromeo 7c61b0e
add pydantic-settings dependency
giancarloromeo e4c30e0
fix bump-pydantic issues
giancarloromeo f25f246
add pydantic-extra-types dependency
giancarloromeo ba507d7
fix bump-pydantic issues
giancarloromeo f2c72fe
fix bump-pydantic issues
giancarloromeo 4f2d46d
fix field names
giancarloromeo e62831c
fix schemas
giancarloromeo 4a2d1c3
fix model_config refs
giancarloromeo 66edc00
fix basic types
giancarloromeo b4b8c87
fix rabbitmq basic types
giancarloromeo 00b2f6d
fix double config field
giancarloromeo 36a15e1
fix projects issues
giancarloromeo ffca801
use pydantic annotated types
giancarloromeo 5812571
continue refactoring
giancarloromeo 08e7b50
fix model validator
giancarloromeo e2895bc
upgrade fastapi encoders
giancarloromeo ac68f4b
fix root models
giancarloromeo c5d2531
fix mapping
giancarloromeo f7356de
fix json serialization
giancarloromeo 2235ec6
fix config dicts merge
giancarloromeo e89ea76
continue upgrading
giancarloromeo 689bf92
continue upgrading
giancarloromeo 7fb1191
continue upgrading
giancarloromeo 78a1571
continue upgrading
giancarloromeo 6361439
continue upgrading
giancarloromeo 2962805
fix emails
giancarloromeo 5afa03f
fix errors
giancarloromeo 53db14a
fix more
giancarloromeo 7db6bc9
continue fixing
giancarloromeo 40913c4
fix node config
giancarloromeo c1ecea5
fix default validator
giancarloromeo bb24bee
fix NodeId type
giancarloromeo e65670d
update node
giancarloromeo 23d2147
fix union mode
giancarloromeo 31695ce
fix constrained str
giancarloromeo 27217c6
fix project locked
giancarloromeo 9b32fa2
fix model configs
giancarloromeo 5e92cc1
fix httpurl
giancarloromeo debd71c
fix service settings labels
giancarloromeo 901d6ee
fix settings labels validators
giancarloromeo bb48cd5
fix osparc variable identifier model
giancarloromeo 4c66094
fix HttpUrl type
giancarloromeo 0baf9ab
continue fixing
giancarloromeo e46c054
fix tests
giancarloromeo 4b1f9fe
fix models equality check
giancarloromeo 2941dea
fix field property
giancarloromeo a1be63c
fix mypy
giancarloromeo be4e077
fix mypy
giancarloromeo 7e134cd
add validate default to thumbnail field
giancarloromeo 3ba5029
fix validation issues
giancarloromeo b328087
fix model validator mode
giancarloromeo 598b9dd
Update packages/models-library/src/models_library/api_schemas_catalog…
giancarloromeo cecf668
fix thumbnail type
giancarloromeo a6a86e0
remove empty model config
giancarloromeo 0abee29
update format
giancarloromeo c4104c7
add typealias
giancarloromeo bafab91
revert bump-pydantic changes
giancarloromeo ea624d1
revert change
giancarloromeo 88ec517
fix union mode
giancarloromeo b62770d
fix default value
giancarloromeo 96a93ac
fix url types
giancarloromeo cbf481e
fix format
giancarloromeo 2c18b4f
fix format
giancarloromeo c97244f
fix S3BucketName validation
giancarloromeo c049903
remove unnecessary todos
giancarloromeo 65ced45
fix codesmell
giancarloromeo 223bbcc
fix codesmell
giancarloromeo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
from pydantic import BaseModel, Extra, Field | ||
from pydantic import BaseModel, ConfigDict, Field | ||
|
||
|
||
class AccessRights(BaseModel): | ||
read: bool = Field(..., description="has read access") | ||
write: bool = Field(..., description="has write access") | ||
delete: bool = Field(..., description="has deletion rights") | ||
|
||
class Config: | ||
extra = Extra.forbid | ||
model_config = ConfigDict(extra="forbid") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from datetime import datetime | ||
from typing import Any, ClassVar, TypeAlias | ||
from typing import Any, TypeAlias | ||
|
||
from models_library.rpc_pagination import PageRpc | ||
from pydantic import BaseModel, Extra, Field, HttpUrl, NonNegativeInt | ||
from pydantic import BaseModel, ConfigDict, Field, HttpUrl, NonNegativeInt | ||
|
||
from ..boot_options import BootOptions | ||
from ..emails import LowerCaseEmailStr | ||
|
@@ -23,8 +23,8 @@ | |
|
||
|
||
class ServiceUpdate(ServiceMetaDataEditable, ServiceAccessRights): | ||
class Config: | ||
schema_extra: ClassVar[dict[str, Any]] = { | ||
model_config = ConfigDict( | ||
json_schema_extra={ | ||
"example": { | ||
# ServiceAccessRights | ||
"accessRights": { | ||
|
@@ -72,6 +72,7 @@ class Config: | |
}, | ||
} | ||
} | ||
) | ||
|
||
|
||
_EXAMPLE_FILEPICKER: dict[str, Any] = { | ||
|
@@ -206,12 +207,11 @@ class ServiceGet( | |
): # pylint: disable=too-many-ancestors | ||
owner: LowerCaseEmailStr | None | ||
|
||
class Config: | ||
allow_population_by_field_name = True | ||
extra = Extra.ignore | ||
schema_extra: ClassVar[dict[str, Any]] = { | ||
"examples": [_EXAMPLE_FILEPICKER, _EXAMPLE_SLEEPER] | ||
} | ||
model_config = ConfigDict( | ||
extra="ignore", | ||
populate_by_name=True, | ||
json_schema_extra={"examples": [_EXAMPLE_FILEPICKER, _EXAMPLE_SLEEPER]}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting that here it just works |
||
) | ||
|
||
|
||
class ServiceGetV2(BaseModel): | ||
|
@@ -229,7 +229,7 @@ class ServiceGetV2(BaseModel): | |
service_type: ServiceType = Field(default=..., alias="type") | ||
|
||
contact: LowerCaseEmailStr | None | ||
authors: list[Author] = Field(..., min_items=1) | ||
authors: list[Author] = Field(..., min_length=1) | ||
giancarloromeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
owner: LowerCaseEmailStr | None | ||
|
||
inputs: ServiceInputsDict | ||
|
@@ -249,11 +249,11 @@ class ServiceGetV2(BaseModel): | |
" It includes current release.", | ||
) | ||
|
||
class Config: | ||
extra = Extra.forbid | ||
alias_generator = snake_to_camel | ||
allow_population_by_field_name = True | ||
schema_extra: ClassVar[dict[str, Any]] = { | ||
model_config = ConfigDict( | ||
extra="forbid", | ||
populate_by_name=True, | ||
alias_generator=snake_to_camel, | ||
json_schema_extra={ | ||
"examples": [ | ||
{ | ||
**_EXAMPLE_SLEEPER, # v2.2.1 (latest) | ||
|
@@ -304,7 +304,8 @@ class Config: | |
], | ||
}, | ||
] | ||
} | ||
}, | ||
) | ||
|
||
|
||
PageRpcServicesGetV2: TypeAlias = PageRpc[ | ||
|
@@ -330,12 +331,11 @@ class ServiceUpdateV2(BaseModel): | |
|
||
access_rights: dict[GroupID, ServiceGroupAccessRightsV2] | None = None | ||
|
||
class Config: | ||
extra = Extra.forbid | ||
alias_generator = snake_to_camel | ||
allow_population_by_field_name = True | ||
model_config = ConfigDict( | ||
extra="forbid", populate_by_name=True, alias_generator=snake_to_camel | ||
giancarloromeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
|
||
assert set(ServiceUpdateV2.__fields__.keys()) - set( # nosec | ||
ServiceGetV2.__fields__.keys() | ||
assert set(ServiceUpdateV2.model_fields.keys()) - set( # nosec | ||
ServiceGetV2.model_fields.keys() | ||
) == {"deprecated"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can you please check if this comment has any relevance and just drop it if not?