-
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
⬆️ pydantic migration catalog #6629
⬆️ pydantic migration catalog #6629
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## pydantic_v2_migration_do_not_squash_updates #6629 +/- ##
===============================================================================
- Coverage 71.53% 71.49% -0.05%
===============================================================================
Files 1094 992 -102
Lines 48641 44968 -3673
Branches 1243 496 -747
===============================================================================
- Hits 34795 32148 -2647
+ Misses 13625 12730 -895
+ Partials 221 90 -131
*This pull request uses carry forward flags. Click here to find out more.
Continue to review full report in Codecov by Sentry.
|
6728e00
to
b051792
Compare
1fad4bb
to
e1d9437
Compare
services/catalog/src/simcore_service_catalog/exceptions/handlers/__init__.py
Outdated
Show resolved
Hide resolved
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.
Thanks
34c9f3e
into
ITISFoundation:pydantic_v2_migration_do_not_squash_updates
Quality Gate passedIssues Measures |
@@ -33,7 +33,9 @@ class ServiceMetaDataEditable(ServiceBaseDisplay): | |||
"If now>=deprecated, the service is retired", | |||
) | |||
classifiers: list[str] | None | |||
quality: dict[str, Any] = {} | |||
quality: dict[str, Any] = Field( | |||
default_factory=dict, json_schema_extra={"default": {}} |
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.
@pcrespov question, is this necessary? is this used in a json schema? well I guess it does not hurt
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.
Yes, you are right. It is only necessary for the models in the OAS. I was writing those systematically and missed this.
limit: StrictInt | StrictFloat | str | ||
reservation: StrictInt | StrictFloat | str | ||
|
||
@model_validator(mode="before") | ||
@classmethod | ||
def _ensure_limits_are_equal_or_above_reservations(cls, values): | ||
# WARNING: this does not validate ON-ASSIGNMENT! |
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.
so how does it work now? what does validate_assignment=True do? nothing?
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.
So on assignment it does not work. What I did is recreating everytime the model. It has only two values so it is not that heavy
assert res.reservation == 10 | ||
|
||
# https://docs.pydantic.dev/latest/api/config/#pydantic.config.ConfigDict.validate_assignment | ||
# before-validators DO NOT work on Assignment!!! |
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.
then why we don't change to an AFTER validator?
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.
I should have tried that... yes. I will do that
"reservation": parse_obj_as(ByteSize, "2Gib"), | ||
}, | ||
}, | ||
_in_bytes = TypeAdapter(ByteSize).validate_python |
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.
not sure I get that one.
but anyway you forgot the typing
@@ -29,4 +30,4 @@ async def _http_error_handler(_: Request, exc: type[BaseException]) -> JSONRespo | |||
content=jsonable_encoder({"errors": [str(exc)]}), status_code=status_code | |||
) | |||
|
|||
return _http_error_handler | |||
return _http_error_handler # type: ignore[return-value] |
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.
why is this one needed? that looks weird.
# for a partial update all members must be Optional | ||
classifiers: list[str] | None = Field(default_factory=list) | ||
owner: PositiveInt | None | ||
# for a partial update all Editable members must be 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.
# for a partial update all Editable members must be Optional | |
# for a partial update all editable members must be Optional |
if service_db.thumbnail | ||
else None | ||
), | ||
thumbnail=HttpUrl(service_db.thumbnail) if service_db.thumbnail else None, |
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.
that does not validate does it?
res_value * _DOCKER_TO_OSPARC_RESOURCE_CONVERTER[res_name], | ||
) | ||
|
||
scale = _DOCKER_TO_OSPARC_RESOURCE_CONVERTER[res_name] |
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.
it is not a necessaryily a scaling. it is a conversion between 2 types.
return f"{randint(0,100)}.{randint(0,100)}.{randint(0,100)}" | ||
def service_version(faker: Faker) -> str: | ||
return ( | ||
f"{faker.random_int(0,100)}.{faker.random_int(0,100)}.{faker.random_int(0,100)}" |
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.
what is the difference with using faker.pyint(min_value=0, max_value=100)
?
mocked_director_service_labels.respond(json={"data": params.simcore_service_label}) | ||
url = URL(f"/v0/services/{service_key}/{service_version}/resources") | ||
response = client.get(f"{url}") | ||
assert response.status_code == 200, f"{response.text}" | ||
data = response.json() | ||
received_resources: ServiceResourcesDict = parse_obj_as(ServiceResourcesDict, data) | ||
received_resources: ServiceResourcesDict = ServiceResourcesDict(**data) |
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.
does this now validate? before it would not
service_key = ( | ||
f"simcore/services/{faker.random_element(['comp', 'dynamic'])}/jupyter-math" | ||
) | ||
service_version = ( | ||
f"{faker.random_int(0,100)}.{faker.random_int(0,100)}.{faker.random_int(0,100)}" | ||
) | ||
url = URL( |
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.
why not re-use the fixture in the other file?
service_key = f"simcore/services/{faker.random_element(['comp', 'dynamic'])}/{faker.pystr().lower()}" | ||
service_version = ( | ||
f"{faker.random_int(0,100)}.{faker.random_int(0,100)}.{faker.random_int(0,100)}" | ||
) |
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.
same here
url = URL( | ||
f"/v0/services/{service_key}/{service_version}/specifications" | ||
).with_query(user_id=user_id) | ||
response = client.get(f"{url}") | ||
assert response.status_code == status.HTTP_200_OK | ||
service_specs = ServiceSpecificationsGet.parse_obj(response.json()) | ||
service_specs = ServiceSpecifications.model_validate(response.json()) |
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.
went from ServiceSpecificationsget to ServiceSpecifications. is that a typo?
@@ -161,7 +161,7 @@ async def test_rpc_catalog_client( | |||
"description": "bar", | |||
"version_display": "this is a nice version", | |||
"description_ui": True, # owner activates wiki view | |||
}, | |||
}, # type: ignore |
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.
??
What do these changes do?
catalog
service to pydantic v2$OPENAPI_GENERATOR_NAME
as in ⬆️ Upgrade openapi generator osparc-simcore-clients#202. This way we can validate the newopenapi.json
environsopenapi.json
and increased api version0.5.0 → 0.6.0
Related issue/s
How to test
Dev-ops checklist
None