-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Support Pydantic 2 #32366
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
Support Pydantic 2 #32366
Conversation
This is a temporary measure to work around dependencies pinning Pydantic to 1.8.x. Will remove this once we fixed all the 2.x incompatibilities.
|
Hey, the CI passes. If I can get some reviews to ensure the changes are OK, I’ll add a commit to remove the build script hack so this is merge-able. |
| dag_id: str | ||
| queued_at: Optional[datetime] | ||
| execution_date: DateTime | ||
| execution_date: datetime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah... So Pydantic just got more "picky" about those. Cool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think they basically switch from isinstance to type identity check, probably for performance concerns (we have similar designs in our own serialisation code). The old behaviour can be brought back with a flag, but this doesn’t need that.
potiuk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending the pydantic>2 hack removal.
This reverts commit f17c6dc.
| # Limit Pydantic to <2.0.0 because it breaks Kubernetes tests and building providers | ||
| # This limit should be removed after https://github.com/apache/airflow/issues/32311 is fixed | ||
| pydantic>=1.10.0,<2.0.0 | ||
| pydantic>=1.10.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Started to see
Unknown warnings generated:
/usr/local/lib/python3.8/site-packages/pydantic/_internal/_config.py:210:Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.0.2/migration/
/usr/local/lib/python3.8/site-packages/pydantic/_internal/_config.py:261:Valid config keys have changed in V2: * 'orm_mode' has been renamed to 'from_attributes'
/usr/local/lib/python3.8/site-packages/pydantic/_internal/_config.py:210:Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.0.2/migration/
/usr/local/lib/python3.8/site-packages/pydantic/_internal/_config.py:210:Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.0.2/migration/
/usr/local/lib/python3.8/site-packages/pydantic/_internal/_config.py:210:Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.0.2/migration/
/usr/local/lib/python3.8/site-packages/pydantic/_internal/_config.py:210:Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.0.2/migration/
/usr/local/lib/python3.8/site-packages/pydantic/_internal/_config.py:210:Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.0.2/migration/
/usr/local/lib/python3.8/site-packages/pydantic/_internal/_config.py:261:Valid config keys have changed in V2: * 'orm_mode' has been renamed to 'from_attributes'
ERROR! There were 8 warnings generated during the import
Example:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#32444 will handle it
|
Hi, @potiuk! I'm interested in finding out when the next release is expected to be made available. Having support for Pydantic 2 would be highly beneficial. |
Why? Could you explain why ? Airlfow 2.7.0 is being released today as we speak (working on it). But in constraints Pydantic is still < 2 - because some of our dependencies limit us, But we have no requiments, and if you are not using any provider that limits pydantic through their dependencies, you might attempt to upgrade and see if it works for you. But you will need to test it and make sure it works. |
If you're asking about the reasons for using Pydantic v2, I'd highlight its significant speed improvement of 5-50 times, along with its enhanced stability and flexibility when compared to v1 (according to its release notes). Regarding why we are waiting for this release, it's because we encountered an error (although I don't remember the details now) while attempting to deploy our airflow (v2.6.3) project that relies on Pydantic v2 models into a Kubernetes cluster. There was an open issue in this repo, and this pull request is expected to address and resolve that problem. |
We are hardly using Pydantic, so improvements would be mariginal, but yes I am very well aware of it, just for "Airflow" it is not highly benefitial (yet). It might be in the future as we have plans for using Pydantic for internal API.
Just checked: 2.7.0 stil has no support for Pydantic: That was likely an overlook as part of the problem with orm-mode at least is solved. So you will have to wait for 2.7.1 |
|
I added limitation removal and scheduled it for 2.7.1 #33507 - seems that the aws-sam-translator removed the limitation last week and are going to be released in a week or two, which should be good as then our CI will test it automatically and we will produce constraints with Pydantic 2. |
Fix #32311 eventually. For CI only at the moment.