-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
π½οΈ Ensure compatibility with Pydantic 2.12.0 #14036
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
Conversation
d7ada00 to
a9d228a
Compare
|
I think we should try to avoid adding new dependency. Maybe something with Detailsfrom dirty_equals import IsOneOf
v1 = {
"age": {
"title": "Age",
"anyOf": [
{"exclusiveMinimum": 0.0, "type": "number"},
{"type": "string"},
],
}
}
v2 = {
"age": {
"title": "Age",
"anyOf": [
{"exclusiveMinimum": 0.0, "type": "number"},
{"type": "string", "pattern": r"^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$"},
],
}
}
expected = {
"age": {
"title": "Age",
"anyOf": [
{"exclusiveMinimum": 0.0, "type": "number"},
IsOneOf(
{"type": "string"},
{"type": "string", "pattern": r"^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$"}
),
],
}
}
assert v1 == expected
assert v2 == expected |
a9d228a to
dbe54cb
Compare
Ah yes, that works too, thanks. Amended. |
dbe54cb to
b5790dc
Compare
|
I just tried running this branch with pydantic 2.12.0a1, and I have 4 failed tests |
These are due to pydantic/pydantic#12028. In that PR, @Viicos wrote:
But I really don't follow what FastAPI is doing here; it seems to be something to do with |
|
I discussed internally with the FastAPI team a while ago about this. The fix I proposed was to use the |
OK, thanks for the advice. a33cc0a implements that. |
dc01ba4 to
a33cc0a
Compare
* run test suite on Python 3.14 * add 3.14 classifier * allow Python pre-release for now * exclude pydantic v1 on Python 3.14 * install pydantic 1.12.0 alpha1 when testing on python 3.14 * preinstall pydantic 1.12.0 alpha1 before anything else
|
I changed the base branch of this PR to |
|
@svlandeg That seems to have resulted in a pile of errors that have nothing to do with this branch. Or am I missing something? |
1869b53 to
cdd831e
Compare
`tests/test_multi_body_errors.py::test_openapi_schema` failed with pydantic 2.12.0a1 due to pydantic/pydantic#11987. Since we're testing the exact contents of the JSON schema, the easiest fix seems to be to add version-dependent handling for this.
Recommended by @Viicos from the Pydantic team.
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
cdd831e to
2ba181e
Compare
I think these are exactly the errors that need resolving - the test suite now actually runs Pydantic 2.12.0a1 on Python 3.14 (rc)? (they're really all mostly versions of the same error, from a quick glance) |
|
PS: @cjwatson: it's fine if you don't want to continue working on those other errors - just let us know - and we'll take over this branch because they need fixing anyway π |
|
Those errors don't appear to happen in my local setup with pydantic 2.12.0a1 on Python 3.13 (which was what I was originally trying to fix with this PR). I'd appreciate it if somebody else could take over the rest of those fixes, yes. |
I think you're right - those additional errors are new in Python 3.14.
Sure thing - I'm going to look into them now. I'll probably merge this PR into our feature branch |
svlandeg
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.
Ok, just to recap and apologies for the earlier confusion!
This PR ensures compatibility with Pydantic 2.12.0, which will be released soon.
In particular, pydantic 2.12.0a1 causes 2 types of failures in our test suite:
test_openapi_schemafails due to pydantic/pydantic#11987 as explained by OP. The test is adjusted to work on both new and older versions of Pydantic.- warnings about using the
aliasattribute with valuewithin theField()function, cf PR pydantic/pydantic#12028. This PR suppresses those warnings when creating type adapters in FastAPI, which seems like a reasonable solution to me.
I had intended to merge these fixes as part of a larger PR to get ready for Python 3.14, but have reverted that and suggest we merge & release this separately to ensure compatibility with the upcoming Pydantic 2.12.0.
Thanks again for your work on this, @cjwatson !
tiangolo
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.
Nice, thank you @cjwatson! π
And thanks a lot for all the help here @YuriiMotov, @Viicos, @svlandeg, @patrick91 π
So cool to come and see all the conversations already done, the code simplified to the minimum, all the context easy to get quickly. Great job, thank you all! π°
I'll release this in the next hours/minutes in FastAPI 0.118.1 π
tests/test_multi_body_errors.py::test_openapi_schemafailed with pydantic 2.12.0a1 due topydantic/pydantic#11987. Since we're testing the exact contents of the JSON schema, the easiest fix seems to be to add version-dependent handling for this.