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

Upgrade Pydantic Dependency to Pydantic 2 #217

Closed
wants to merge 20 commits into from

Conversation

esciara
Copy link

@esciara esciara commented Nov 24, 2023

Resolves #134

Description

All comments are already on the issue.

Probably need a bit more cleaning up.

It is to be noted that there is a change of behavior by pydantic where by casting is no longer done on attributes. Not knowing which behavior was desired, I changed the tests rather that the code, making sure I wrote a # TODO to make it clearly visible.

Checklist

@cla-bot cla-bot bot added the cla:yes label Nov 24, 2023
@esciara esciara changed the base branch from qmalcolm--pydantic-2-support to main November 24, 2023 23:49
@esciara esciara force-pushed the qmalcolm--pydantic-2-support branch from 8806001 to 4b6bf94 Compare November 25, 2023 00:09
pyproject.toml Outdated
@@ -20,7 +20,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"pydantic~=1.10",
"pydantic~=2.5",
Copy link

@r-richmond r-richmond Nov 26, 2023

Choose a reason for hiding this comment

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

Suggested change
"pydantic~=2.5",
"pydantic>=2.5",

You'll probably want to wait for someone from DBT to approve but it would be great to have a looser constraint here and adding an upper bound when/if it becomes necessary.

Copy link
Author

Choose a reason for hiding this comment

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

Hi. Yes I will let them say what to do, as I only followed how it was done before.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Howdy! I actually think we should stick with the ~= specification. Pydantic follows semantic versioning pretty well, at least I believe it does. As such we should expect a Pydantic 3 to be breaking. It's also generally less painful after the fact to loosen the top end as compared to having to tighten it.

I have a separate question though, is there a specific reason to use ~=2.5 instead of ~=2.0 here? Are we using any 2.5 specific functionality in this change that requires 2.5 to be the minimum?

Copy link
Author

Choose a reason for hiding this comment

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

No specific reason. I probably should not have done that.

I will change it tomorrow and do some tests on lower versions than 2.5, just to make sure nothing breaks.

Copy link
Author

@esciara esciara Nov 30, 2023

Choose a reason for hiding this comment

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

I confirm that tests pass even with pydantic ==2.0.0, so no need for ~=2.5. I put it back to ~=2.0.

@QMalcolm the floor is yours.

@robcresswell
Copy link

It looks like this has drifted and may need rebasing @esciara, are you able to do that? Still needs someone from dbt to review unfortunately, they're busy folks

@esciara
Copy link
Author

esciara commented Dec 8, 2023

It looks like this has drifted and may need rebasing @esciara, are you able to do that? Still needs someone from dbt to review unfortunately, they're busy folks

Yes will do (before the end of the weekend hopefully).

@robcresswell
Copy link

Awesome! I was hesitant to ask. This is my last hard blocker on a pydantic 2 migration unfortunately, as I imagine it is for others. Thankyou so much for working on it!

@bernard-arcturisdata
Copy link

Came to add huge thanks to @esciara for the legwork and add a +1 to the PR, hit this dependency conflict when trying to upgrade dbt-core. Without it we'll be stuck on v1.5.9 for a while!

@esciara esciara force-pushed the qmalcolm--pydantic-2-support branch from 28a9226 to 547ff92 Compare December 8, 2023 21:13
@esciara
Copy link
Author

esciara commented Dec 8, 2023

You are welcome @bernard-arcturisdata . 🤗

@robcresswell => done.

Would be great if this could be merged before needing rebasing again: it was kinda hard to get back into it, and the last fixing commit I did gave me a bit of a hard time.

@esciara esciara force-pushed the qmalcolm--pydantic-2-support branch from 0e3e60d to aeeadc2 Compare December 8, 2023 21:26
@r-richmond
Copy link

I don't know much It will help but https://getdbt.slack.com/archives/C50NEBJGG/p1699935532376859 is a relevant slack thread in DBT's core-dev channel. May be worth more activity in there to help encourage DBT to look at it.

@QMalcolm QMalcolm changed the title Qmalcolm pydantic 2 support Upgrade Pydantic Dependency to Pydantic 2 Dec 11, 2023
@QMalcolm
Copy link
Collaborator

As we've been reviewing this we also realized we are likely going to have to support both Pydantic 1 and Pydantic 2 for quite some time. About 60 percent of people using Pydantic are still on Pydantic 1. Pydantic 2 is very exciting. It's faster, and we plan to support it in 0.5 of DSI. Although we'd love to cut directly to just supporting Pydantic 2, that'll likely cause immediate pain for community.

In regards to this PR, we still want to get it in. Currently we're investigating whether the changes in this PR will also work with any Pydantic 1 versions (hopefully at least 1.10.x). If that is not the case, we're then going to investigate if that would be possible with some slight tweaks to this PR. If that does not work, there are some crunchier ways for us to support both which we'd likely do in a separate PR if it came to that.

@QMalcolm
Copy link
Collaborator

@esciara I also want to thank you again for this work. This is a very well put together PR.

Regardless of what direction we end up having to take, this work has forced us to dive deeper into this issue sooner than we likely would have otherwise.

@esciara
Copy link
Author

esciara commented Dec 12, 2023

@QMalcolm your are welcome. 🤗

@esciara
Copy link
Author

esciara commented Dec 12, 2023

By the way, it seems to me that fastapi supports both pydantic v1 and v2. I have not clue how they do this, but it might be interesting to have a look.

@QMalcolm QMalcolm mentioned this pull request Dec 12, 2023
3 tasks
@r-richmond
Copy link

r-richmond commented Dec 12, 2023

Although we'd love to cut directly to just supporting Pydantic 2, that'll likely cause immediate pain for community.

At the risk of over stepping my bounds. Isn't the immediate pain they'd experience limited to only the inability to update to any version of DBT that requires the new DSI until they update their dependencies?

Whereas currently the pain for those of us in the community who have updated to pydantic>2 is that we are restricted to the versions of DBT <=1.5 (which do not conflict with pydantic >2)

... I agree that supporting both would be the smoothest for the community but that might also introduce a significant maintenance burden, slowing development on this library. Anyways just wanted to make sure you considered all that. Nevertheless thank you both for working on this. As you might have guessed it's become a significant pain point for me 😁

@bernardcooke53
Copy link

In the spirit of "trying to help", I raised a PR #227 with what I'd call an interim solution - it's not as nice as being able to "just upgrade" but I think it would go a long way towards mitigating the impact of having the dependency pinned 🙂

@QMalcolm
Copy link
Collaborator

QMalcolm commented Jan 4, 2024

@esciara I think for the time being we're going to close this PR. We want to include this PR in the future, but that future is likely 1+ year(s) away. At that time we'll look to re-open this PR 🙂

@QMalcolm QMalcolm closed this Jan 4, 2024
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.

[Feature] Bump pydantic to >=2.0.0
6 participants