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

Begin supporting Pydantic 2 (without dropping support for Pydantic 1) #238

Merged
merged 5 commits into from
Jan 3, 2024

Conversation

QMalcolm
Copy link
Collaborator

@QMalcolm QMalcolm commented Dec 21, 2023

Resolves #134

Description

After community and internal discussions we decided the best path forward was to support both Pydantic 1 and Pydantic 2 for the time being as we can't drop Pydantic 1 yet, but we also need to allow for Pydantic 2. We decided the tidiest way to do this would be via shimming. This PR adds the shim, directs pydantic imports to it, loosens the pydantic requirement to allow for pydantic 2, and ensure our testing checks both moving forward.

Also, I want shout out other PRs that worked to address this issue #217 and #227 as well as the people who worked on them (@esciara and @bernardcooke53 respectively). Their work was fundamental to making the changes that this PR contains, and they should be considered contributors on this effort.

Checklist

We are going to need to support pydantic 1 for some time. We think currently
that we'll have to support it for atleast another year. However, we also
need to begin supporting pydantic 2. Thus we need this shim to have the
flexibility of supporting both.

I have also run `hatch build` and ensured that this shim _does_ get included
in the resulting tarball. In the upcoming commits, we'll switch over direct
pydantic imports to instead use this shim, and then loosen the version in the
pyproject config.
@cla-bot cla-bot bot added the cla:yes label Dec 21, 2023
@QMalcolm
Copy link
Collaborator Author

@esciara & @bernardcooke53 can you both confirm you are okay with me including y'all as authors in the changie log? ❤️

@bernardcooke53
Copy link

@QMalcolm absolutely! 🚀

@QMalcolm QMalcolm requested a review from tlento December 21, 2023 23:50
@QMalcolm QMalcolm added the House keeping Not a feature, not a bug, just some house keeping label Dec 21, 2023
This is necessary because the typing for v1 stuff breaks when using
Pydantic 2. We can stop doing this once we actually migrate off of
Pydantic 1 implementations.
@QMalcolm QMalcolm force-pushed the qmalcolm--134-pydantic-2-via-shimming branch from cf601fc to 1e6245a Compare December 22, 2023 00:00
@QMalcolm
Copy link
Collaborator Author

Also because we aren't dropping support for Pydantic 1 in this work, I think we can backport this to 0.4.latest. Which would then allow for people using dbt-core and Pydantic 2 to upgrade dbt-core 1.7 and not have to continue waiting until dbt-core 1.8. But we should do some more testing first.

@esciara
Copy link

esciara commented Dec 22, 2023

@esciara & @bernardcooke53 can you both confirm you are okay with me including y'all as authors in the changie log? ❤️

Sure is!

@esciara
Copy link

esciara commented Dec 22, 2023

I can see that you ensure compatibility by keeping the code as is and importing the package pydantic.v1 in case Pydantic v2 is selected. Probably the smartest choice! 👍

So I guess that when you drop support for Pydantic v1, my PR #217 might become useful. I leave you do decide how to handle it (close it, keep it open, add a comment to it, other...).

@RoelantDL
Copy link

Great improvement! Does anyone have an estimate on when this pull request will be merged?

@QMalcolm
Copy link
Collaborator Author

QMalcolm commented Jan 3, 2024

@RoelantDL With review approval this morning, it'll be merged today. It's worth noting that merging it won't make it immediately available in dbt-core. Core 1.7.x runs on dbt-semantic-interfaces 0.4.x, thus we need to backport this to 0.4.latest and then release an 0.4.3 of dbt-semantic-interfaces. At that point, you'll have refresh your environment to pull in the new version of dbt-semantic-interfaces.

@QMalcolm QMalcolm merged commit 70cb735 into main Jan 3, 2024
14 checks passed
@QMalcolm QMalcolm deleted the qmalcolm--134-pydantic-2-via-shimming branch January 3, 2024 18:17
QMalcolm added a commit that referenced this pull request Jan 3, 2024
[BACKPORT] #238 to 0.4.latest (Pydantic 2 Support)
@QMalcolm QMalcolm added the Backport 0.4.latest Fix should be backported to 0.4.latest label Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport 0.4.latest Fix should be backported to 0.4.latest cla:yes House keeping Not a feature, not a bug, just some house keeping
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Bump pydantic to >=2.0.0
5 participants