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

716 updating pydantic version #721

Open
wants to merge 104 commits into
base: main
Choose a base branch
from
Open

Conversation

Antonyjin
Copy link
Member

@Antonyjin Antonyjin commented Nov 11, 2024

Pydantic need to be updated to v2

Jira tickets : ALEPH-150

Self proofreading checklist

  • The new code clear, easy to read and well commented.
  • New code does not duplicate the functions of builtin or popular libraries.

Changes

Upgrading to pydantic 2.

  • Removing every deprecated functions
  • Adapt the parsing with pydantic 2 which is more strict (model_dump / model_dump_json)
  • Modify the usage of dotenv to adapt with pydantic 2

Antonyjin and others added 15 commits October 31, 2024 20:30
Started the migration using the tool dump-pydantic.
It only do some parts, but there are mch to do, not finished.
Now, have to change and update manually.
Typing is more strict in pydantic v2
…dation support

Validation was failing with Pydantic v2 due to stricter date formats and unhandled JSON errors.

Adapted the exceptions so we handle format/validation with changes bringed by
pydantic v2
The migration to Pydantic 2 bringed some warnings and deprecated
funtions.

Fixing them all manually
The return value for url was string but now pydantic is strict and need a good
type

Changing str to HttpUrl for url
…l_dump_json`

In Pydantic v2, the `.json()` method has been replaced with `.model_dump_json()` for serializing json
Updated the mock in `test_check_internet_wrong_result_code` to use `.model_dump_json`
instead of `.json` to align with this change.
Pydantic 2 add more fields while returning error such as `url`, `ctx` or `input`
Adapting the test to the new format given by pydantic
Adding a / with the url makes the url containing two slashes which break the url

Removing it
@Antonyjin Antonyjin linked an issue Nov 11, 2024 that may be closed by this pull request
Changed @root_validator to @model_validator(mode="after") for checking data after the model is created.
Updated values to use a more flexible type for Pydantic v2.
Accessed values as a dictionary (values["payload"]) instead of using values.payload.
Copy link

codecov bot commented Nov 12, 2024

Codecov Report

Attention: Patch coverage is 84.78261% with 14 lines in your changes missing coverage. Please review.

Project coverage is 63.37%. Comparing base (73013a2) to head (592c45f).

Files with missing lines Patch % Lines
src/aleph/vm/storage.py 57.14% 3 Missing ⚠️
src/aleph/vm/orchestrator/views/authentication.py 94.59% 1 Missing and 1 partial ⚠️
src/aleph/vm/conf.py 93.75% 1 Missing ⚠️
src/aleph/vm/controllers/qemu/instance.py 0.00% 1 Missing ⚠️
src/aleph/vm/orchestrator/reactor.py 0.00% 1 Missing ⚠️
src/aleph/vm/orchestrator/run.py 50.00% 1 Missing ⚠️
src/aleph/vm/orchestrator/tasks.py 50.00% 1 Missing ⚠️
src/aleph/vm/orchestrator/views/__init__.py 50.00% 1 Missing ⚠️
src/aleph/vm/orchestrator/views/operator.py 0.00% 1 Missing ⚠️
src/aleph/vm/pool.py 50.00% 1 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #721      +/-   ##
==========================================
+ Coverage   63.33%   63.37%   +0.03%     
==========================================
  Files          77       77              
  Lines        6854     6861       +7     
  Branches      576      577       +1     
==========================================
+ Hits         4341     4348       +7     
- Misses       2325     2326       +1     
+ Partials      188      187       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Antonyjin Antonyjin force-pushed the 716-updating-pydantic-version branch from bd06710 to 950d1cd Compare November 19, 2024 12:03
Antonyjin and others added 12 commits November 19, 2024 13:04
Previously, `os.makedirs` was called directly on variables like `MESSAGE_CACHE`
or `CODE_CACHE`, which could be `None`. This caused issues with `mypy` and potential
runtime errors since `os.makedirs` does not handle `None`.

The fix ensures these variables are checked for `None` before calling `os.makedirs`,
preventing invalid operations and aligning with type checks.
Previously, `os.makedirs` was called directly on variables like `MESSAGE_CACHE`
or `CODE_CACHE`, which could be `None`. This caused issues with `mypy` and potential
runtime errors since `os.makedirs` does not handle `None`.

The fix ensures these variables are checked for `None` before calling `os.makedirs`,
preventing invalid operations and aligning with type checks.

fix: wrong name
@Antonyjin Antonyjin force-pushed the 716-updating-pydantic-version branch from f8ce889 to d96e9ca Compare November 22, 2024 17:28
@Antonyjin Antonyjin marked this pull request as ready for review November 22, 2024 17:43
@Antonyjin Antonyjin force-pushed the 716-updating-pydantic-version branch from 4b5dfd5 to 631401e Compare February 25, 2025 16:39
@Antonyjin Antonyjin self-assigned this Mar 20, 2025
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.

Updating Pydantic version
3 participants