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

[MAINTENANCE] Pydantic 2.0 support #8604

Merged
merged 39 commits into from
Sep 7, 2023

Conversation

NathanFarmer
Copy link
Contributor

@NathanFarmer NathanFarmer commented Aug 22, 2023

Add pydantic compatibility module and update imports

Migration guide for reference:
https://docs.pydantic.dev/dev-v2/migration/

Note: this PR does not aim to fully migrate to pydantic v2 patterns but simply to remove the upper bound on v2 so that downstream dependencies and users can install pydantic v2 along with great_expectations.


  • Description of PR changes above includes a link to an existing GitHub issue
  • PR title is prefixed with one of: [BUGFIX], [FEATURE], [DOCS], [MAINTENANCE], [CONTRIB]
  • Code is linted - run invoke lint (uses black + ruff)
  • Appropriate tests and docs have been updated

@NathanFarmer NathanFarmer self-assigned this Aug 22, 2023
@netlify
Copy link

netlify bot commented Aug 22, 2023

Deploy Preview for niobium-lead-7998 canceled.

Name Link
🔨 Latest commit 35f4025
🔍 Latest deploy log https://app.netlify.com/sites/niobium-lead-7998/deploys/64fa0ab6b3f6710008648252

@github-actions github-actions bot added the core label Aug 22, 2023
@ghost
Copy link

ghost commented Aug 22, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@Kilo59 Kilo59 self-assigned this Sep 6, 2023
@Kilo59 Kilo59 marked this pull request as ready for review September 7, 2023 10:49
Comment on lines 59 to +65
- run: invoke fmt --check
- name: Marker-coverage-check
run: |
invoke marker-coverage
- name: Type-check
run: |
invoke type-check --ci --pretty
invoke type-check --ci --pretty --check-stub-sources
- name: Marker-coverage-check
run: invoke marker-coverage
Copy link
Contributor

Choose a reason for hiding this comment

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

I swapped the order of these to get faster feedback on typing issues

@@ -405,6 +404,24 @@ jobs:
- name: Run the tests
run: invoke ci-tests -m unit --xdist --slowest=10 --timeout=2.0

pydantic-v1:
Copy link
Contributor

Choose a reason for hiding this comment

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

Added a test for our min version of pydantic now that the other tests will be installing v2

Comment on lines +1 to +3
# this is higher than our min version but is the earliest version that actually works
# TODO: update our min version or fix gx for our current min version
pydantic==1.10.8
Copy link
Contributor

@Kilo59 Kilo59 Sep 7, 2023

Choose a reason for hiding this comment

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

Our min version of pydantic in our requirements file is 1.9 but gx actually breaks at import time on this version, and it looks like we were never testing against this version in our CI.
This does not appear related to moving to pydantic v2.

I will create followup tickets for taking the action here.

great_expectations/compatibility/pydantic.py Show resolved Hide resolved
Comment on lines +10 to +21
from pydantic.v1 import (
AnyUrl,
UrlError,
error_wrappers,
errors,
fields,
generics,
json,
networks,
schema,
typing,
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

How does it work if I'm creating a V2 Base Model and I want to use one of these classes? I guess we can cross that bridge when we get there.

Copy link
Contributor

@Kilo59 Kilo59 Sep 7, 2023

Choose a reason for hiding this comment

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

That won't be possible yet, without some conditional imports.

We would need some kind of pydantic_v2 compatibility module that works like our other optional dependencies (sqlalchemy).
Unless we just decide to drop pydantic v1, but I think we need to let the ecosystem catch up before we can do that.

@@ -2,7 +2,7 @@ black[jupyter]==23.3.0 # Linting / code style
Click>=7.1.2 # CLI tooling
cookiecutter==2.1.1 # Project templating
mypy==1.5.1 # Type checker
pydantic>=1.0,<2.0 # Needed for mypy plugin
pydantic>=1.0 # Needed for mypy plugin
Copy link
Contributor

Choose a reason for hiding this comment

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

Should make me 1.10.8?

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, I don't understand why we have this entry in cli/requirements at all.
It being in our core requirements should be enough.

@Kilo59 Kilo59 enabled auto-merge (squash) September 7, 2023 17:39
@Kilo59 Kilo59 merged commit 091fc1d into develop Sep 7, 2023
@Kilo59 Kilo59 deleted the mod-coding-pydantic-v2-compatibility branch September 7, 2023 18:08
jskrzypek pushed a commit to jskrzypek/great_expectations that referenced this pull request Aug 1, 2024
Pull in changes from great-expectations#8604 MR to enable pydantic v2 compat for 0.15.50

I dropped the code changes that corresponded to net-new changes since
0.15.50, and also added the re-pointed imports to other locations that
imported from pydantic.

There was one import of typing_extensions.override that I also pulled in
the compatibility change for, as compatibility/pydantic.py imports
compatibility/not_imported.py, which imports
compatibility/typing_extensions.py.

Co-authored-by: Gabriel <[email protected]>
jskrzypek pushed a commit to jskrzypek/great_expectations that referenced this pull request Aug 2, 2024
Pull in changes from great-expectations#8604 MR to enable pydantic v2 compat for 0.15.50

I dropped the code changes that corresponded to net-new changes since
0.15.50, and also added the re-pointed imports to other locations that
imported from pydantic.

There was one import of typing_extensions.override that I also pulled in
the compatibility change for, as compatibility/pydantic.py imports
compatibility/not_imported.py, which imports
compatibility/typing_extensions.py.

Co-authored-by: Gabriel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pydantic V2 support
3 participants