-
Notifications
You must be signed in to change notification settings - Fork 32
⬆️ Upgrade API Server service (Pydantic v2) #6580
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
Changes from 14 commits
aa37a25
e085708
d32c059
37fcf8d
3d88400
7d2cb94
f439884
7ed9993
9b9b74c
ff99950
fbf6463
b2742f5
523e530
ae3e882
ad0cf2b
593df29
fd1ae8d
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 |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
|
|
||
| from models_library.folders import FolderID | ||
| from models_library.workspaces import WorkspaceID | ||
| from pydantic import Field, HttpUrl, field_validator | ||
| from pydantic import ConfigDict, Field, HttpUrl, field_validator | ||
|
|
||
| from ..api_schemas_long_running_tasks.tasks import TaskGet | ||
| from ..basic_types import LongTruncatedStr, ShortTruncatedStr | ||
|
|
@@ -78,14 +78,18 @@ class ProjectGet(OutputSchema): | |
| ui: EmptyModel | StudyUI | None = None | ||
| quality: dict[str, Any] = {} | ||
| dev: dict | None = None | ||
| permalink: ProjectPermalink = FieldNotRequired() | ||
| workspace_id: WorkspaceID | None | ||
| folder_id: FolderID | None | ||
| permalink: ProjectPermalink | None = FieldNotRequired() | ||
| workspace_id: WorkspaceID | None = None | ||
| folder_id: FolderID | None = None | ||
|
|
||
| _empty_description = field_validator("description", mode="before")( | ||
| none_to_empty_str_pre_validator | ||
| ) | ||
|
|
||
| model_config = ConfigDict( | ||
| frozen=False | ||
|
Contributor
Author
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. Superclass is
Member
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. thanks! I guess these went off with the re-creation of the branch. how did you find that out? in the warnings of pytest??
Contributor
Author
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 a test there was a direct assignment of a field in that model. |
||
| ) | ||
|
|
||
|
|
||
| TaskProjectGet: TypeAlias = TaskGet | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,10 @@ class WalletGet(OutputSchema): | |
| created: datetime | ||
| modified: datetime | ||
|
|
||
| model_config = ConfigDict( | ||
| frozen=False | ||
|
Contributor
Author
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. Superclass is
Member
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. same question
Contributor
Author
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 a test there was a direct assignment of a field in that model. |
||
| ) | ||
|
|
||
|
|
||
| class WalletGetWithAvailableCredits(WalletGet): | ||
| available_credits: Decimal | ||
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,13 +8,13 @@ | |
| class CapturedParameterSchema(BaseModel): | ||
| title: str | None = None | ||
| type_: Literal["str", "int", "float", "bool"] | None = Field(None, alias="type") | ||
| pattern: str | None | ||
| pattern: str | None = None | ||
| format_: Literal["uuid"] | None = Field(None, alias="format") | ||
| exclusiveMinimum: bool | None | ||
| minimum: int | None | ||
| anyOf: list["CapturedParameterSchema"] | None | ||
| allOf: list["CapturedParameterSchema"] | None | ||
| oneOf: list["CapturedParameterSchema"] | None | ||
| exclusiveMinimum: bool | None = None | ||
| minimum: int | float | None = None | ||
| anyOf: list["CapturedParameterSchema"] | None = None | ||
| allOf: list["CapturedParameterSchema"] | None = None | ||
| oneOf: list["CapturedParameterSchema"] | None = None | ||
|
Contributor
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. Out of curiosity: Why do these have default values now? I believe this is used quite extensively for our testing, so I would try to be as strict as possible in our model.
Contributor
Author
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.
Member
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. but still. these were thought as "required" but can be "none" and now they are "non-required". we already had that discussion if I remember well. you showed that pydantic v1 was misbehaving. but still the intent was of having them "required". I would double check with @bisgaard-itis and @pcrespov here |
||
|
|
||
| class Config: | ||
| validate_always = True | ||
|
|
@@ -34,15 +34,15 @@ def preprocess_type_(cls, val): | |
| @model_validator(mode="after") | ||
| @classmethod | ||
| def check_compatibility(cls, values): | ||
| type_ = values.get("type_") | ||
| pattern = values.get("pattern") | ||
| format_ = values.get("format_") | ||
| anyOf = values.get("anyOf") | ||
| allOf = values.get("allOf") | ||
| oneOf = values.get("oneOf") | ||
| type_ = values.type_ | ||
|
Member
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. this should be a root_validator or the pydantic v2 pendant instead. instead of playing with strings, you would have the self.pattern |
||
| pattern = values.pattern | ||
| format_ = values.format_ | ||
| anyOf = values.anyOf | ||
| allOf = values.allOf | ||
| oneOf = values.oneOf | ||
| if not any([type_, oneOf, anyOf, allOf]): | ||
| type_ = "str" # this default is introduced because we have started using json query params in the webserver | ||
| values["type_"] = type_ | ||
| values.type_ = type_ | ||
| if type_ != "str" and any([pattern, format_]): | ||
| msg = f"For {type_=} both {pattern=} and {format_=} must be None" | ||
| raise ValueError(msg) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,8 +15,8 @@ reqs: ## compiles pip requirements (.in -> .txt) | |
|
|
||
|
|
||
| # specification of the used openapi-generator-cli (see also https://github.com/ITISFoundation/openapi-generator) | ||
| OPENAPI_GENERATOR_NAME := itisfoundation/openapi-generator-cli-openapi-generator-v4.2.3 | ||
| OPENAPI_GENERATOR_TAG := v0 | ||
| OPENAPI_GENERATOR_NAME := openapitools/openapi-generator-cli | ||
|
Contributor
Author
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. For OpenAPI Spec validation we use the official tool, our fork is obsolete and doesn't support OpenAPI Spec 3.1.x. |
||
| OPENAPI_GENERATOR_TAG := latest | ||
|
Contributor
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. Would it make sense to pin the version? I believe this is used in the tests (checking compatibility of openapi specs) and not pinning the version creates a "loose end". If suddenly a bug/change is introduced in the tool we may start seeing strange compatibility failures in our ci |
||
| OPENAPI_GENERATOR_IMAGE := $(OPENAPI_GENERATOR_NAME):$(OPENAPI_GENERATOR_TAG) | ||
|
|
||
| define _create_and_validate_openapi | ||
|
|
@@ -25,10 +25,6 @@ define _create_and_validate_openapi | |
| export API_SERVER_DEV_FEATURES_ENABLED=$1; \ | ||
| python3 -c "import json; from $(APP_PACKAGE_NAME).main import *; print( json.dumps(the_app.openapi(), indent=2) )" > $@ | ||
|
|
||
| # patching version until tools adapted | ||
| @sed -i 's/"openapi": "3.1.0",/"openapi": "3.0.2",/g' $@ | ||
|
|
||
|
|
||
| # validates OAS file: $@ | ||
| docker run --rm \ | ||
| --volume "$(CURDIR):/local" \ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
@matusdrobuliak66 confirmed that
workspace_idandfolder_idare optionalThere 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.
these are only for jsonschema generation right? what confuses me is when you say "optional" this does not mean with a default of None