-
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
Changes from 55 commits
6c6bebc
533bdd1
c1bbc52
76f0fc6
55b72c7
df01a19
41b8797
7c61b0e
e4c30e0
f25f246
ba507d7
f2c72fe
4f2d46d
e62831c
4a2d1c3
66edc00
b4b8c87
00b2f6d
36a15e1
ffca801
5812571
08e7b50
e2895bc
ac68f4b
c5d2531
f7356de
2235ec6
e89ea76
689bf92
7fb1191
78a1571
6361439
2962805
5afa03f
53db14a
7db6bc9
40913c4
c1ecea5
bb24bee
e65670d
23d2147
31695ce
27217c6
9b32fa2
5e92cc1
debd71c
901d6ee
bb48cd5
4c66094
0baf9ab
e46c054
4b1f9fe
2941dea
a1be63c
be4e077
7e134cd
3ba5029
b328087
598b9dd
cecf668
a6a86e0
0abee29
c4104c7
bafab91
ea624d1
88ec517
b62770d
96a93ac
cbf481e
2c18b4f
c97244f
c049903
65ced45
223bbcc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ arrow | |
jsonschema | ||
orjson | ||
pydantic[email] | ||
pydantic-settings | ||
pydantic-extra-types |
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") |
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,23 +23,23 @@ | |
|
||
|
||
class ServiceUpdate(ServiceMetaDataEditable, ServiceAccessRights): | ||
class Config: | ||
schema_extra: ClassVar[dict[str, Any]] = { | ||
model_config = ConfigDict( | ||
json_schema_extra={ | ||
"example": { | ||
# ServiceAccessRights | ||
"accessRights": { | ||
1: { | ||
"execute_access": False, | ||
"write_access": False, | ||
}, | ||
}, # type: ignore[dict-item] | ||
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. In pydantic v2:
and
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. and here we use an int instead of a str. Is that invalid JSON? 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. Does this mean that example has to be stored as json.dumps? |
||
2: { | ||
"execute_access": True, | ||
"write_access": True, | ||
}, | ||
}, # type: ignore[dict-item] | ||
44: { | ||
"execute_access": False, | ||
"write_access": False, | ||
}, | ||
}, # type: ignore[dict-item] | ||
}, | ||
# ServiceMetaData = ServiceCommonData + | ||
"name": "My Human Readable Service Name", | ||
|
@@ -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"} |
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?