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

Create version 1 of Pydantic 2 breaking libs #201

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

sinclert-canonical
Copy link
Contributor

This PR creates version 1 of those libraries that would suffer breaking changes due to the support of Pydantic 2:

  • data_models.
  • upgrade.

Given that this is the first PR that bumps the major version of some of the libraries, some code shuffling was required to give the repository a cohesive view of what is still in v0, and what is available both in v0 and v1.


Pydantic 2 specific changes:

Pydantic 2 breaking changes can be seen in commit d08fbaa.

Code substitutions
- from pydantic import validator
+ from pydantic import field_validator

- from pydantic import root_validator
+ from pydantic import model_validator

- field.outer_type_
+ field.annotation

- obj.dict
+ obj.model_dump

- obj.__fields__
+ obj.model_fields

- type(self.dependency_model)(**json.loads(deps))
+ type(self.dependency_model).model_validate_json(deps)

- json.dumps(self.dependency_model.dict())
+ self.dependency_model.model_dump_json()

Code shuffling changes:

  • Moved + adapted all previous integration tests into tests/v0/integration.
  • Moved + adapted all previous unit tests into tests/v0/unit.
  • Copied + adapted data_models.py and upgrade.py tests into tests/v1/unit.
  • Copied + adapted data_models.py and upgrade.py libs into libs/charms/data_platform_libs/v1.
  • Adapted Tox.ini environments to allow for -v0 and -v1 suffixes.
  • Adapted CI workflow to use the new Tox environments.

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.

1 participant