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

[DEP] Bump Pydantic to V2.6 #116

Merged
merged 17 commits into from
Apr 16, 2024
Merged

[DEP] Bump Pydantic to V2.6 #116

merged 17 commits into from
Apr 16, 2024

Conversation

Mildophin
Copy link
Collaborator

@Mildophin Mildophin commented Apr 11, 2024

Description

This PR updates the version of Pydantic required by pasqal-cloud from V1.10 to V2.6.

Breaking changes

Now pasqal-cloud needs Pydantic >= 2.6.0 to run.

Checklist

  • The title of the PR follows the right format: [{Label}] {Short Message}. Label examples: IMPROVEMENT, FIX, REFACTORING... Short message is about what your PR changes.

Versioning (PASQAL developers only)

  • Update the version of pasqal-cloud in _version.py following the changes in your PR and by using semantic versioning.

Documentation

  • Update CHANGELOG.md with a description explaining briefly the changes to the users.

Tests

  • Unit tests have been added or adjusted.
  • Tests were run locally.

Internal tests pipeline (PASQAL developers only)

  • Update and run the internal tests while targeting the branch of this PR.
    If your PR hasn't changed any functionality, it still needs to be validated against internal tests.

After updating the version (PASQAL developers only)

  • Open a PR on the internal tests that updates the version used for the pasqal-cloud backward compatibility tests.

Mildophin and others added 8 commits April 9, 2024 16:33
- fix optional fields
- fix batch private field (_client): add __init__
- refacto of ordered_jobs attribute creation
- add a minimal version for pydantic
- apply pydantic conventions
- refacto of how to set _client attribute
@Mildophin Mildophin self-assigned this Apr 11, 2024
@validator("configuration", pre=True)
@jobs.setter
def jobs(self, _: Any) -> None:
# Does not set 'jobs' as it is built from 'ordered_jobs'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not totally convinced by my explanation, if you have a better manner of explaining it, I am all ears.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What are you trying to explain?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am trying to explain we can't set jobs as it depending of ordered_jobs, it is just that ordered jobs is a list of dict, and jobs a dict with a different key for each job, made from ordered list. Anyway I might change the logic as it is very confusing, I remember I had to do this trick with the property before Pydantic V2 but things can be easier now. I will have a look.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Quick suggestion, feel free to iterate over it

Suggested change
# Does not set 'jobs' as it is built from 'ordered_jobs'
# Override the jobs setter to be a no-op.
# `jobs` is a read-only attribute which is derived from the `ordered_jobs` key.

@Mildophin Mildophin force-pushed the mv/update-to-pydantic-V2 branch from e6da099 to 68eb594 Compare April 11, 2024 14:54
setup.py Show resolved Hide resolved
@Mildophin Mildophin force-pushed the mv/update-to-pydantic-V2 branch from c806a0e to 53546a3 Compare April 11, 2024 15:22
@Mildophin Mildophin changed the title [DEP] Bump Pydantic to V2 [DEP] Bump Pydantic to V2.6 Apr 11, 2024
@Mildophin Mildophin marked this pull request as ready for review April 11, 2024 15:26
@Mildophin Mildophin linked an issue Apr 11, 2024 that may be closed by this pull request
def result_link_to_result(
cls, result: Optional[Dict[str, Any]], values: Dict[str, Any]
cls, v: Optional[Dict[str, Any]], info: ValidationInfo
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the single letter variable changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To match pydantic way of using their feature: https://docs.pydantic.dev/latest/concepts/validators/

Copy link
Collaborator

@Augustinio Augustinio Apr 15, 2024

Choose a reason for hiding this comment

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

As I mentioned above I don't think it's advantageous to use v rather than being explicit with result

@validator("configuration", pre=True)
@jobs.setter
def jobs(self, _: Any) -> None:
# Does not set 'jobs' as it is built from 'ordered_jobs'
Copy link
Collaborator

Choose a reason for hiding this comment

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

What are you trying to explain?

configuration: Union[Dict[str, Any], BaseConfig, None],
values: Dict[str, Any],
v: Union[Dict[str, Any], BaseConfig, None],
info: ValidationInfo,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the variable name changes?

Copy link
Collaborator Author

@Mildophin Mildophin Apr 12, 2024

Choose a reason for hiding this comment

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

Variable name changed for the same reason as I explained on your first comment, to match Pydantic documentation.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's ok in the documentation to keep things generic but I think for our purpose here it's more readable and maintainable to keep configuration and not v.

values["ordered_jobs"] = ordered_jobs_list
return values
jobs_received = data.get("jobs", [])
data["ordered_jobs"] = [{**job, "_client": data["_client"]} for job in jobs_received]
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you really want to reduce this you can replace jobs_received with data.get("jobs", []).

You aren't saving much in the way of readability

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I feel like it will be too much in this case if I replace jobs_received, too many information on the same line. I think this format is clear and compact enough. Anyway I think this is more of a question of preference. If you think it is not relevant I can change it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The 2nd line at a glance is obscure so not sure readability or clarity means anything there. I'm just pointing out you can reduce it further if we want, you do what you prefer

Copy link
Collaborator

@Augustinio Augustinio left a comment

Choose a reason for hiding this comment

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

LGTM aside from the loss of explicitness in the method parameters.

configuration: Union[Dict[str, Any], BaseConfig, None],
values: Dict[str, Any],
v: Union[Dict[str, Any], BaseConfig, None],
info: ValidationInfo,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's ok in the documentation to keep things generic but I think for our purpose here it's more readable and maintainable to keep configuration and not v.

def result_link_to_result(
cls, result: Optional[Dict[str, Any]], values: Dict[str, Any]
cls, v: Optional[Dict[str, Any]], info: ValidationInfo
Copy link
Collaborator

@Augustinio Augustinio Apr 15, 2024

Choose a reason for hiding this comment

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

As I mentioned above I don't think it's advantageous to use v rather than being explicit with result

Copy link
Collaborator

@MatthieuMoreau0 MatthieuMoreau0 left a comment

Choose a reason for hiding this comment

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

Looks good overall, a couple small remarks

pasqal_cloud/batch.py Outdated Show resolved Hide resolved
pasqal_cloud/batch.py Outdated Show resolved Hide resolved
@validator("configuration", pre=True)
@jobs.setter
def jobs(self, _: Any) -> None:
# Does not set 'jobs' as it is built from 'ordered_jobs'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Quick suggestion, feel free to iterate over it

Suggested change
# Does not set 'jobs' as it is built from 'ordered_jobs'
# Override the jobs setter to be a no-op.
# `jobs` is a read-only attribute which is derived from the `ordered_jobs` key.

pasqal_cloud/job.py Outdated Show resolved Hide resolved
@Mildophin Mildophin merged commit 9d7bceb into dev Apr 16, 2024
5 checks passed
@Mildophin Mildophin deleted the mv/update-to-pydantic-V2 branch April 16, 2024 17:38
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.

Pasqal-Cloud dependency with Pydantic (Forschungszentrum Jülich)
5 participants