Skip to content

Migrate from Pydantic V1 to V2 #293

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

Merged
merged 24 commits into from
Apr 11, 2025
Merged

Conversation

Antonyjin
Copy link
Member

@Antonyjin Antonyjin commented Oct 21, 2024

This issue aims to upgrade the pydantic version to v2.

Related Jira tickets : ALEPH-149

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.
  • An LLM was used to review the new code and look for simplifications.

Changes

Many functions will be deprecated using pydantic v2 and completly unusable when using pydantic v3. So all of them have been replaced with the good ones.

How to test

hatch run testing-test-cov

Notes

At the moment, aleph-message and aleph-sdk-python version use the github link. We need to wait the release of these two repositories and then put the right version instead of the github URL

@Antonyjin Antonyjin linked an issue Oct 21, 2024 that may be closed by this pull request
@Antonyjin Antonyjin marked this pull request as draft October 21, 2024 15:44
Copy link

Failed to retrieve llama text: POST 504:

504 Gateway Time-out


The server didn't respond in time.

Copy link

codecov bot commented Oct 25, 2024

Codecov Report

Attention: Patch coverage is 48.78049% with 21 lines in your changes missing coverage. Please review.

Project coverage is 60.51%. Comparing base (f5c89eb) to head (6955f06).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/aleph_client/commands/utils.py 44.44% 8 Missing and 2 partials ⚠️
src/aleph_client/commands/instance/__init__.py 25.00% 3 Missing ⚠️
src/aleph_client/commands/message.py 50.00% 3 Missing ⚠️
src/aleph_client/commands/program.py 40.00% 3 Missing ⚠️
src/aleph_client/commands/files.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #293      +/-   ##
==========================================
- Coverage   61.60%   60.51%   -1.09%     
==========================================
  Files          18       18              
  Lines        3183     3199      +16     
  Branches      448      451       +3     
==========================================
- Hits         1961     1936      -25     
- Misses        984     1024      +40     
- Partials      238      239       +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.

Aleph-message and sdk now uses pydantic v2 but no released yet
Using the github link atm and wait for the release.
When upgrading the pydantic version, some function are / will become
deprecated. replacing them in those files.
Added `default=extended_json_encoder` to `json.dumps()` to handle serialization
of non-native JSON types, such as dates and other complex objects.

Replacing function that are / will be deprecated in pydantic v2 and v3
Pydantic>=2 is not compatible with fastapi<0.100.0
Conflit between pydantic and yamlfix
black did not pass
With Pydantic v2, strict type validation is enforced. The type field is expected
to have the exact value "POST" as a literal.
@Antonyjin Antonyjin force-pushed the antonyjin-upgrade-pydantic-version branch from 8f522ba to e621718 Compare December 2, 2024 17:20
Antonyjin and others added 10 commits December 3, 2024 02:27
- Unused varible deleted
- Replacing parse_obj() by model_validate()
- Replacing copy() by model_copy()
- Replacing dict() by model_dump()
…cause of some changes on aleph_message

Before any change, there were classes dedicated to the size of Ephemeral and Persistent class such as
PersistentVolumeSizeMb and EphemeralVolumeSizeMb.
Now, the size is included inside the classes EphemeralVolume and PersistentVolume so have to access the size
by another method.

- Creating a function to get the max and min size, that way it is more rigorous
- Calling this function to get max and min size of the different volumes
- Refactor the Dict() class inside the mocks test file to allow any key-value pair to be
passed to the model.
@Antonyjin Antonyjin marked this pull request as ready for review March 14, 2025 15:16
Arnaud made some changes about getting hashes that were better but I deleted by mistakes

Putting back his code
@nesitor nesitor self-requested a review April 9, 2025 17:18
@nesitor nesitor changed the title Antonyjin upgrade pydantic version Migrate from Pydantic V1 to V2 Apr 9, 2025
@aleph-im aleph-im deleted a comment from github-actions bot Apr 9, 2025
Antonyjin and others added 4 commits April 10, 2025 18:50
Reverting changes about accessing data of PersistentVolumeSizeMib and EphemeralVolumeSize
- creating a function to access annotated type because we can no longer do Persistent.le to get the data
@nesitor nesitor self-requested a review April 11, 2025 09:32
@nesitor nesitor merged commit 6a9d348 into master Apr 11, 2025
12 of 14 checks passed
@nesitor nesitor deleted the antonyjin-upgrade-pydantic-version branch April 11, 2025 09:45
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.

Upgrade pydantic version
2 participants