Skip to content
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

kernelci.api.models: fix pydantic warnings for url fields #2745

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

JenySadadia
Copy link
Collaborator

@JenySadadia JenySadadia commented Nov 25, 2024

Related to kernelci/kernelci-api#560

Fix the below pydantic v2 warnings:

Expected `url` but got `str` with value - serialized value may not be as expected

This is due to fields such as artifacts and revision.url expect pydantic Url type and afterwards convert the values to str to store it in mongo DB and for json response. Change field types to str and use TypeAdapter to validate Url values before validating them as strings.

Discussion thread for the issue:
pydantic/pydantic#6395

Fix the below pydantic v2 warnings:
```
Expected `url` but got `str` with value - serialized value may not be as expected
```
This is due to fields such as `artifacts` and `revision.url`
expect pydantic `Url` type and afterwards convert the values
to `str` to store it in mongo DB and for json response.
Change field types to `str` and use `TypeAdapter` to validate
`Url` values before validating them as strings.

Discussion thread for the issue:
pydantic/pydantic#6395

Signed-off-by: Jeny Sadadia <[email protected]>
Copy link
Contributor

@pawiecz pawiecz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -117,7 +120,8 @@ class Revision(BaseModel):
tree: str = Field(
description="git tree of the revision"
)
url: Annotated[AnyUrl | FileUrl, AfterValidator(str)] = Field(
url: Annotated[str, BeforeValidator(
lambda value: str(any_url_adapter.validate_python(value)))] = Field(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support for FileURLs without host set is dropped here but I don't think any kind of currently supported Storage types allowed them anyway

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AnyUrl allows FileUrl as well. That's why dropped it from here.

@nuclearcat nuclearcat added this pull request to the merge queue Nov 27, 2024
Merged via the queue into kernelci:main with commit fa656f1 Nov 27, 2024
4 checks passed
@JenySadadia JenySadadia deleted the fix-pydantic-warnings-for-url branch November 27, 2024 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants